Skip to content

util: explicitly chmod generated files to enforce permissions - #614

Merged
JegadishD merged 1 commit into
canonical:mainfrom
vpashaiev:fix/umask-file-permissions
Sep 18, 2026
Merged

JegadishD merged 1 commit into
canonical:mainfrom
vpashaiev:fix/umask-file-permissions

Conversation

@vpashaiev

Copy link
Copy Markdown
Contributor

When netplan generate runs under a restrictive umask (such as 0077), files created by g_file_set_contents_full() end up with permissions 0600 instead of 0640. As a result, systemd-networkd (running unprivileged as systemd-network:systemd-network) cannot read /run/systemd/network/10-netplan-*.network, causing network configuration to fail on boot.

This PR explicitly calls chmod() after chown() in _netplan_g_string_free_to_file_with_permissions() so that the intended file mode is enforced regardless of the caller's umask. It also adds a unit test in test_netplan_misc to verify file permissions under umask 0077.

Addresses feedback from @puida on Launchpad #2164636.
Fixes: https://bugs.launchpad.net/ubuntu/+source/netplan.io/+bug/2164636

@vpashaiev
vpashaiev force-pushed the fix/umask-file-permissions branch from dad2ee7 to cf5000f Compare September 14, 2026 13:19
When netplan generate is executed under a restrictive umask (such as 0077),
files written by g_file_set_contents_full() end up with mode 0600 instead
of 0640. This prevents systemd-networkd from reading the generated
.network files, breaking network configuration.

Explicitly call chmod() after chown() so target permissions
are guaranteed regardless of the caller's umask.

Also add a unit test in test_netplan_misc to verify file creation
under a restrictive umask.

LP: #2164636
Signed-off-by: Viktor Pashaiev <w.paszajew@gmail.com>
@vpashaiev
vpashaiev force-pushed the fix/umask-file-permissions branch from cf5000f to e0f4cc7 Compare September 14, 2026 13:55
@JegadishD JegadishD added the review-list review-list tag is applied to PR that are to be considered for review with priority. label Sep 16, 2026
@JegadishD JegadishD self-assigned this Sep 17, 2026

@JegadishD JegadishD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@vpashaiev Thanks for the PR

@JegadishD
JegadishD merged commit b74171c into canonical:main Sep 18, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-list review-list tag is applied to PR that are to be considered for review with priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants