From: Filip Schauer <f.schauer@proxmox.com>
To: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] superseded: [PATCH container 2/2] oci create: honor `User` from OCI image config
Date: Wed, 21 Jan 2026 17:05:53 +0100 [thread overview]
Message-ID: <0af550e7-dc75-446f-a98b-deec1ee39031@proxmox.com> (raw)
In-Reply-To: <ndm6jv2yzv4aq25255w3frhifoesikk2gq2vlxqvdfhuvxkdrq@qsxnxwvwtzue>
On 15/01/2026 14:17, Wolfgang Bumiller wrote:
>> + if (my $usercfg = $oci_config_get_checked_scalar->('User')) {
> This code should be factored into a separate sub.
>
>> + my ($user, $group) = $usercfg =~ /^([^:]+)(?::([^:]+))?$/
>> + or die "OCI config value for 'User' has an invalid format\n";
>> +
>> + my $etc_passwd = "$rootdir/etc/passwd";
>> + my $etc_group = "$rootdir/etc/group";
>> +
>> + # Scan file, match column $match_index against $match_val, return value at $ret_index
>> + my $lookup_field = sub {
>> + my ($file, $match_index, $match_val, $ret_index) = @_;
>> +
>> + open(my $fh, '<', $file) or return undef;
>> + while (my $line = <$fh>) {
>> + my @fields = split(/:/, $line);
> A subtlety about this sub is that currently the last field also includes
> the trailing `\n`. Should probably add a comment, or `chomp` it away,
> even if we currently don't use the final field via `$ret_index`.
>
>> + if (defined($fields[$match_index]) && $fields[$match_index] eq $match_val) {
>> + return $fields[$ret_index];
>> + }
>> + }
>> + return undef;
>> + };
>> +
>> + my $get_supplementary_groups = sub {
>> + my ($username) = @_;
>> +
>> + my @groups;
>> + open(my $fh, '<', $etc_group) or return undef;
>> + while (defined(my $line = <$fh>)) {
>> + push @groups, $1
>> + if ($line =~ m/^[^:]*:[^:]*:([^:]*):(?:[^,]*,)*$username(?:,|$)/);
> Username comes from the outside and is only limited to not containing a
> colon. To use it inside a regex you'd have to quote it as
> `\Q$username\E`.
>
> Safer would be to do what you do in `$lookup_field` and just split on
> `:` then `,` then grep with `eq`.
Feedback implemented in v2:
https://lore.proxmox.com/pve-devel/20260121160020.280888-1-f.schauer@proxmox.com
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2026-01-21 16:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 17:41 [pve-devel] [PATCH container 0/2] " Filip Schauer
2025-12-15 17:41 ` [pve-devel] [PATCH container 1/2] config: add `lxc.init.uid`/`gid`/`groups` keys Filip Schauer
2025-12-15 17:41 ` [pve-devel] [PATCH container 2/2] oci create: honor `User` from OCI image config Filip Schauer
2026-01-15 13:18 ` Wolfgang Bumiller
2026-01-21 16:05 ` Filip Schauer [this message]
2025-12-16 12:03 ` [pve-devel] [PATCH container 0/2] " Maximiliano Sandoval
2025-12-16 18:13 ` Filip Schauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0af550e7-dc75-446f-a98b-deec1ee39031@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
--cc=w.bumiller@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox