Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on limiting what names an agent can register by the seliux context. #1023

Merged
merged 15 commits into from
Jan 14, 2025

Conversation

alexlarsson
Copy link
Contributor

@alexlarsson alexlarsson commented Jan 10, 2025

This extends how we configure allowed node names, and allows us to configure per-node-name requirements.

A node name can now either be in the allowed names list, or the controller config (or via a .d dropin) can have a section named "[node FOO]", with a key Allowed=true.

If a named node is allowed, we look for the "RequiredSelinuxContext" key in the above section, and if it is set, we require the connecting agent to have the given selinux context type.

Note: We already disallow most processes (except bluechi_agent_t and haproxy_t) to connect to the controller, but with this we can limit what names they can claim. For example, we could enforce a special name for an agent running in qm.

@coveralls
Copy link

coveralls commented Jan 13, 2025

Coverage Status

coverage: 82.411% (+0.06%) from 82.356%
when pulling 092a92a on alexlarsson:uds-selinux
into 8907577 on eclipse-bluechi:main.

@alexlarsson alexlarsson force-pushed the uds-selinux branch 2 times, most recently from 7fd0435 to db66289 Compare January 13, 2025 11:13
@alexlarsson alexlarsson marked this pull request as ready for review January 13, 2025 16:15
Copy link
Member

@engelmi engelmi left a comment

Choose a reason for hiding this comment

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

We should definitely add a few integration tests for this change.
Since the GH CI runners use Ubuntu VMs, we can't really run SELinux tests in the GH CI - only via Packit/Testing Farm these tests would be (reliably) running. I think we have already integration tests like this tagged with testing-farm-container.
We can postpone this to another PR, though. If yes, then I'll create an issue to track it.

src/controller/controller.c Outdated Show resolved Hide resolved
src/controller/node.c Outdated Show resolved Hide resolved
src/libbluechi/common/string-util.c Show resolved Hide resolved
src/controller/node.c Outdated Show resolved Hide resolved
This parses a full selinux context and returns the type.
Will be needed later.
This is mainly doable for UDS sockets, but will allow us to limit
what name can register by the selinux label.
This extends how we configure allowed node names, and allows us to
configure per-node-name requirements.

A node name can now either be in the AllowedNodeNames list, or the
in a section named "[node FOO]", with a key Allowed=true. The later
is very useful from a .d dropin file.

If a named node is allowed, we look for the "RequiredSelinuxContext"
key in the above section, and if it is set, we require the connecting
agent to have the given selinux context type.

Note: We already disallow most processes (except bluechi_agent_t and
haproxy_t) to connect to the controller, but with this we can limit
what names they can claim. For example, we could enforce a special
name for an agent running in qm.
I didn't change these likes, but clang-format complains about them,
so fix them.
Current code breaks with these and they don't seem to be helpful.

These were the warnings:

src/libbluechi/common/protocol.h:107:9: error: inital values in enum 'JobState' are not consistent, consider explicit initialization of all, none or only the first enumerator [readability-enum-initial-value,-warnings-as-errors]
  107 | typedef enum JobState {
      |         ^
  108 |         JOB_WAITING,
      |                     = 0
  109 |         JOB_RUNNING,
      |                     = 1
src/libbluechi/common/protocol.h:116:9: error: inital values in enum 'UnitActiveState' are not consistent, consider explicit initialization of all, none or only the first enumerator [readability-enum-initial-value,-warnings-as-errors]
  116 | typedef enum UnitActiveState {
      |         ^
  117 |         UNIT_ACTIVE,
      |                     = 0
  118 |         UNIT_RELOADING,
      |                        = 1
  119 |         UNIT_INACTIVE,
      |                       = 2
  120 |         UNIT_FAILED,
      |                     = 3
  121 |         UNIT_ACTIVATING,
      |                         = 4
  122 |         UNIT_DEACTIVATING,
      |                           = 5
  123 |         UNIT_MAINTENANCE,
      |                          = 6
  124 |         _UNIT_ACTIVE_STATE_MAX,
      |                                = 7
src/libbluechi/bus/utils.c:329:26: error: '*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses,-warnings-as-errors]
  329 |         char *r = malloc(strlen(s) * 3 + 1);
      |                          ^~~~~~~~~~~~~
      |                          (            )
This lets us build strings easier.
Now that we use more than one section, make the debug output
make sense by printing the section headers.
Copy link
Member

@engelmi engelmi left a comment

Choose a reason for hiding this comment

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

LGTM

I created #1026 to keep track of the integration tests we have to write for this.

@alexlarsson alexlarsson merged commit 1bd96dc into eclipse-bluechi:main Jan 14, 2025
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants