Skip to content

Conversation

@borismw
Copy link
Contributor

@borismw borismw commented May 22, 2025

Refers to issue #239. If the paperless_ngx_conf_usermap_uid variable is set to an id different from 1000, the unarchive fails to unpack files and change their ownership. This seems to be because the user unpacking the archive is different from the one owning the files.

This PR adds a lookup step to find out the correct user name with id == 1000 in cause paperless_ngx_conf_usermap_uid != 1000. The user name stored in the variable _paperless_ngx_untar_username will then later be used as the become_user in the unarchive step.

Note that with this solution

  • if there's no user with id 1000 yet
  • and paperless_ngx_conf_usermap_uid is not defined
    the lookup step will fail even though the user might perchance be created with the id 1000.

In order to prevent this one might to either have to move the system user creation step to an earlier stage or make paperless_ngx_conf_usermap_uid mandatory. I was not sure if it was okay to go down any of these routes.

@borismw borismw force-pushed the fix/unarchive-fails-for-user-other-than-id-1000 branch from 80be532 to 4da6829 Compare May 22, 2025 22:46
@borismw borismw force-pushed the fix/unarchive-fails-for-user-other-than-id-1000 branch from 4da6829 to 2c92b58 Compare May 22, 2025 22:48
@borismw borismw changed the title fix:unarchive fails for user id != 1000 fix: unarchive fails for user id != 1000 Aug 19, 2025
@github-actions github-actions bot added the bug Something isn't working label Aug 19, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where unarchiving fails when the paperless_ngx_conf_usermap_uid is set to a value different from 1000. The fix involves determining the correct username for user ID 1000 and using it as the become_user for unarchive operations.

  • Adds logic to lookup the username for user ID 1000 when paperless_ngx_conf_usermap_uid is not 1000
  • Updates unarchive tasks to use the determined username as become_user
  • Modifies permission handling to work with the new unarchive approach

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
tasks/preparation/platform.yml Adds username lookup logic for user ID 1000 based on paperless_ngx_conf_usermap_uid configuration
tasks/paperless_ngx/release_files.yml Updates unarchive process to use determined username and adjusts permission handling
tasks/base_dependencies/python.yml Applies the same unarchive fix for Python source downloads

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

key: 1000
split: ':'
register: _getent_query_result

Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line assumes that the getent query will always return exactly one result with UID 1000. If no user with UID 1000 exists, accessing [0] will cause an IndexError. Add error handling or validation to ensure the query returns results before accessing the first element.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +31
when: (paperless_ngx_conf_usermap_uid is undefined) or paperless_ngx_conf_usermap_uid != "1000"

- name: Set fact username for user with id 1000
ansible.builtin.set_fact:
_paperless_ngx_untar_username: "{{ paperless_ngx_system_user }}"
when: (paperless_ngx_conf_usermap_uid is defined) and paperless_ngx_conf_usermap_uid == "1000"
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison uses string \"1000\" in line 31 but integer comparison in line 26. This inconsistency could lead to unexpected behavior if paperless_ngx_conf_usermap_uid is defined as an integer. Use consistent data types for comparison, preferably converting to string or integer consistently.

Suggested change
when: (paperless_ngx_conf_usermap_uid is undefined) or paperless_ngx_conf_usermap_uid != "1000"
- name: Set fact username for user with id 1000
ansible.builtin.set_fact:
_paperless_ngx_untar_username: "{{ paperless_ngx_system_user }}"
when: (paperless_ngx_conf_usermap_uid is defined) and paperless_ngx_conf_usermap_uid == "1000"
when: (paperless_ngx_conf_usermap_uid is undefined) or (paperless_ngx_conf_usermap_uid | string) != "1000"
- name: Set fact username for user with id 1000
ansible.builtin.set_fact:
_paperless_ngx_untar_username: "{{ paperless_ngx_system_user }}"
when: (paperless_ngx_conf_usermap_uid is defined) and (paperless_ngx_conf_usermap_uid | string) == "1000"

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +31
when: (paperless_ngx_conf_usermap_uid is undefined) or paperless_ngx_conf_usermap_uid != "1000"

- name: Set fact username for user with id 1000
ansible.builtin.set_fact:
_paperless_ngx_untar_username: "{{ paperless_ngx_system_user }}"
when: (paperless_ngx_conf_usermap_uid is defined) and paperless_ngx_conf_usermap_uid == "1000"
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison uses string \"1000\" in line 31 but integer comparison in line 26. This inconsistency could lead to unexpected behavior if paperless_ngx_conf_usermap_uid is defined as an integer. Use consistent data types for comparison, preferably converting to string or integer consistently.

Suggested change
when: (paperless_ngx_conf_usermap_uid is undefined) or paperless_ngx_conf_usermap_uid != "1000"
- name: Set fact username for user with id 1000
ansible.builtin.set_fact:
_paperless_ngx_untar_username: "{{ paperless_ngx_system_user }}"
when: (paperless_ngx_conf_usermap_uid is defined) and paperless_ngx_conf_usermap_uid == "1000"
when: (paperless_ngx_conf_usermap_uid is undefined) or (paperless_ngx_conf_usermap_uid | string) != "1000"
- name: Set fact username for user with id 1000
ansible.builtin.set_fact:
_paperless_ngx_untar_username: "{{ paperless_ngx_system_user }}"
when: (paperless_ngx_conf_usermap_uid is defined) and (paperless_ngx_conf_usermap_uid | string) == "1000"

Copilot uses AI. Check for mistakes.
{{ _install_tempdir_state.files[0].path }}
{%- endif -%}
- name: Pepare permissions of tmp dir for untaring paperless-ngx sources
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in task name: 'Pepare' should be 'Prepare' and 'untaring' should be 'untarring'.

Suggested change
- name: Pepare permissions of tmp dir for untaring paperless-ngx sources
- name: Prepare permissions of tmp dir for untarring paperless-ngx sources

Copilot uses AI. Check for mistakes.
path: "{{ paperless_ngx_dependency_install_tmp_dir }}"
register: _python_archive_dir

- name: Pepare permissions of tmp dir for unarchiving python sources
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in task name: 'Pepare' should be 'Prepare'.

Suggested change
- name: Pepare permissions of tmp dir for unarchiving python sources
- name: Prepare permissions of tmp dir for unarchiving python sources

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant