Jira (PUP-11591) file type parses MLS file contexts incorrectly.

16 views
Skip to first unread message

Steve Traylen (Jira)

unread,
Jul 11, 2022, 10:34:02 AM7/11/22
to puppe...@googlegroups.com
Steve Traylen created an issue
 
Puppet / Bug PUP-11591
file type parses MLS file contexts incorrectly.
Issue Type: Bug Bug
Affects Versions: PUP 7.17.0
Assignee: Unassigned
Components: Types and Providers
Created: 2022/07/11 7:33 AM
Environment:

CentOS 7 and 9 at least.

Priority: Normal Normal
Reporter: Steve Traylen

Puppet Version: 7.17.0
Puppet Server Version: 7.17.0
OS Name/Version: CentOS 7 and CentOS 9 at least.

When the file type encounters an selinux context with an MLS component.

e.g. note the extra unusual c110,c289 below.

ls -lZ /etc/httpd/conf/http.conf 
-rw-r--r--. 1 root root system_u:object_r:httpd_config_t:s0:c110,c289 6 Jul 11 16:12 /etc/httpd/conf/http.conf

the selrange is incorrectly parsed as 's0:c110,c289' and not 's0' as it should be.

The result is this considered a mismatch with desired configuration and
puppet attempts to set the selrange to s0 which it does.

However the mis parse remains and so puppet will forever try and change the
selrange from ' 's0:c110,c289' to 's0'

Steps to reproduce.

Install CentOS 7 or 9 (probably 8 is okay as well just not tested.

dnf install -y podman httpd

The context of /etc/httpd/conf/httpd.conf is now a perfectly normal:

ls -lZ /etc/httpd/conf/httpd.conf
-rw-r--r--. 1 root root system_u:object_r:httpd_config_t:s0 12005 Jun 16 18:44 /etc/httpd/conf/httpd.conf

and puppet parses this perfectly as

# puppet resource file /etc/httpd/conf/httpd.conf
file { '/etc/httpd/conf/httpd.conf':
  ensure   => 'file',
  content  => '{sha256}55b3dd635b5a56ebee1fe890d7372ec25c215cef0c0f3dd8f2bc5ae6e323da12',
  ctime    => '2022-07-11 15:37:15 +0200',
  group    => 0,
  mode     => '0644',
  mtime    => '2022-06-16 18:44:10 +0200',
  owner    => 0,
  provider => 'posix',
  selrange => 's0',
  selrole  => 'object_r',
  seltype  => 'httpd_config_t',
  seluser  => 'system_u',
  type     => 'file',
}

Now introduce MLS to equation.

podman run -it -v  /etc/httpd:/etc/httpd:Z fedora /bin/bash

and now outside the container:

ls -lZ /etc/httpd/conf/http.conf
-rw-r--r--. 1 root root system_u:object_r:httpd_config_t:s0:c110,c289 6 Jul 11 16:12 /etc/httpd/conf/http.conf

Note that the c110,c289 has quite correctly appeared.

However the resource parse of this is:

file { '/etc/httpd/conf/http.conf':
  ensure   => 'file',
  content  => '{sha256}c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
  provider => 'posix',
  selrange => 's0:c110,c289',
  selrole  => 'object_r',
  seltype  => 'httpd_config_t',
  seluser  => 'system_u',
}

The selrange is wrong and it should be still 's0'

This is mismatch as compared to

# matchpathcon /etc/httpd/conf/http.conf 
/etc/httpd/conf/http.conf       system_u:object_r:httpd_config_t:s0

and so puppet pointless trys to set the selrange back to s0 which it does
but this is then a loop.

# puppet resource file /etc/httpd/conf/http.conf 'content=foobar'
Notice: /File[/etc/httpd/conf/http.conf]/selrange: selrange changed 's0:c110,c289' to 's0'
file { '/etc/httpd/conf/http.conf':
  ensure   => 'file',
  content  => '{sha256}c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
  provider => 'posix',
  selrange => 's0:c110,c289',
  selrole  => 'object_r',
  seltype  => 'httpd_config_t',
  seluser  => 'system_u',
}

Desired Behavior:

selrange , selrold, seltype should be parsed correctly for the case when
an MLS is present in the file context.

Actual Behavior:

Puppet try to set the wrongly parsed state of the system for ever.

More information:

MLS https://www.redhat.com/en/blog/how-selinux-separates-containers-using-multi-level-security

This regex needs to be a little smarter basically.

https://github.com/puppetlabs/puppet/blob/main/lib/puppet/util/selinux.rb#L79

to parse the first token as s0 and not s0:c110,c289

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo

Steve Traylen (Jira)

unread,
Jul 11, 2022, 10:40:03 AM7/11/22
to puppe...@googlegroups.com
Steve Traylen updated an issue
Change By: Steve Traylen
*Puppet Version:* 7.17.0
*Puppet Server Version:* 7.17.0
*OS Name/Version:* CentOS 7 and CentOS 9 at least.


When the file type encounters an selinux context with an MLS component.

e.g. note the extra unusual c110,c289 below.

{noformat}
ls -lZ /etc/httpd/conf/http.conf
-rw-r--r--. 1 root root system_u:object_r:httpd_config_t:s0:c110,c289 6 Jul 11 16:12 /etc/httpd/conf/http.conf
{noformat}

the selrange is incorrectly parsed as  's0:c110,c289' and not 's0' as it should be.

The result is this considered a mismatch with desired configuration and
puppet attempts to set the selrange to s0 which it does.

However the mis parse remains and so puppet will forever try and change the
selrange from ' 's0:c110,c289' to 's0'

Steps to reproduce.

Install CentOS 7 or 9 (probably 8 is okay as well just not tested.

dnf install -y podman httpd

The context of /etc/httpd/conf/httpd.conf is now a perfectly normal:

{noformat}
ls -lZ /etc/httpd/conf/httpd.conf
-rw-r--r--. 1 root root system_u:object_r:httpd_config_t:s0 12005 Jun 16 18:44 /etc/httpd/conf/httpd.conf

{noformat}

and puppet parses this perfectly as

{noformat}

# puppet resource file /etc/httpd/conf/httpd.conf
file { '/etc/httpd/conf/httpd.conf':
  ensure   => 'file',
  content  => '{sha256}55b3dd635b5a56ebee1fe890d7372ec25c215cef0c0f3dd8f2bc5ae6e323da12',
  ctime    => '2022-07-11 15:37:15 +0200',
  group    => 0,
  mode     => '0644',
  mtime    => '2022-06-16 18:44:10 +0200',
  owner    => 0,
  provider => 'posix',
  selrange => 's0',
  selrole  => 'object_r',
  seltype  => 'httpd_config_t',
  seluser  => 'system_u',
  type     => 'file',
}

{noformat}

Now introduce MLS to equation.

{noformat}
podman run -it -v  /etc/httpd:/etc/httpd:Z fedora /bin/bash
{noformat}

and  now outside the container:

{noformat}
ls -lZ /etc/httpd/conf/http.conf
-rw-r--r--. 1 root root system_u:object_r:httpd_config_t:s0:c110,c289 6 Jul 11 16:12 /etc/httpd/conf/http.conf
{noformat}

Note that the c110,c289 has quite correctly appeared.

However the resource parse of this is:

{noformat}
file { '/etc/httpd/conf/http.conf':
  ensure   => 'file',
  content  => '{sha256}c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
  provider => 'posix',
  selrange => 's0:c110,c289',
  selrole  => 'object_r',
  seltype  => 'httpd_config_t',
  seluser  => 'system_u',
}
{noformat}

The selrange is wrong and it should be still 's0'

This is mismatch as compared to


{noformat}

# matchpathcon /etc/httpd/conf/http.conf
/etc/httpd/conf/http.conf       system_u:object_r:httpd_config_t:s0
{noformat}

and so puppet pointless trys pointlessly tries to set the selrange back to s0 which it does
but this is then a loop.

{noformat}
# puppet resource file /etc/httpd/conf/http.conf 'content=foobar'
Notice: /File[/etc/httpd/conf/http.conf]/selrange: selrange changed 's0:c110,c289' to 's0'
file { '/etc/httpd/conf/http.conf':
  ensure   => 'file',
  content  => '{sha256}c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
  provider => 'posix',
  selrange => 's0:c110,c289',
  selrole  => 'object_r',
  seltype  => 'httpd_config_t',
  seluser  => 'system_u',
}

{noformat}


*Desired Behavior:*


selrange , selrold, seltype should be parsed correctly for the case when
an MLS is present in the file context.


*Actual Behavior:*


Puppet try to set the wrongly parsed state of the system for ever.

More information:

MLS

This regex needs to be a little smarter basically.

[ https://github.com/puppetlabs/puppet/blob/main/lib/puppet/util/selinux.rb#L79 ]

to parse the
first last token as s0 and not s0:c110,c289

Lisa Ross (Jira)

unread,
Jul 28, 2022, 10:09:03 AM7/28/22
to puppe...@googlegroups.com
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Lisa Ross (Jira)

unread,
Jul 28, 2022, 10:10:01 AM7/28/22
to puppe...@googlegroups.com

Lisa Ross (Jira)

unread,
Jul 28, 2022, 10:10:02 AM7/28/22
to puppe...@googlegroups.com
Lisa Ross updated an issue
Change By: Lisa Ross
Sprint: Phoenix 2022-08-17

Nirupama Mantha (Jira)

unread,
Jul 28, 2022, 11:32:03 AM7/28/22
to puppe...@googlegroups.com

Nirupama Mantha (Jira)

unread,
Jul 28, 2022, 11:32:03 AM7/28/22
to puppe...@googlegroups.com
Nirupama Mantha updated an issue
 
Change By: Nirupama Mantha
Sprint: Phoenix 2022-08-17

Morgan Rhodes (Jira)

unread,
Aug 17, 2022, 12:39:01 PM8/17/22
to puppe...@googlegroups.com
Morgan Rhodes updated an issue
Change By: Morgan Rhodes
Sprint: Phoenix 2022- 08 09 - 31 14

Josh Cooper (Jira)

unread,
Aug 31, 2022, 1:17:03 PM8/31/22
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Labels: needs-validation

Morgan Rhodes (Jira)

unread,
Aug 31, 2022, 1:40:03 PM8/31/22
to puppe...@googlegroups.com
Morgan Rhodes updated an issue
Change By: Morgan Rhodes
Sprint: Phoenix 2022-09-14
Reply all
Reply to author
Forward
0 new messages