Skip to content

Now checks for privileged system users instead of groups + Unit tests#1

Merged
wtripp180901 merged 30 commits into
mainfrom
feat/system-users
Jun 30, 2025
Merged

Now checks for privileged system users instead of groups + Unit tests#1
wtripp180901 merged 30 commits into
mainfrom
feat/system-users

Conversation

@wtripp180901

Copy link
Copy Markdown
Collaborator

No description provided.

@wtripp180901 wtripp180901 changed the title Now checks for privileged system users instead of groups Now checks for privileged system users instead of groups + units test May 30, 2025
@wtripp180901 wtripp180901 changed the title Now checks for privileged system users instead of groups + units test Now checks for privileged system users instead of groups + Unit tests May 30, 2025
@wtripp180901

Copy link
Copy Markdown
Collaborator Author

image tag for e00a1fd : 66ae32e

@wtripp180901
wtripp180901 marked this pull request as ready for review June 2, 2025 14:41
Comment thread .github/workflows/unit-test.yml
Comment thread src/main.go Outdated
// Returns true if user is a service account with correct privileges or a privileged internal K8s system user
func isPrivilegedSystemUser(user string, protectedNamespaces []string) bool {

systemAccountRegex, _ := regexp.Compile("system:.+")

@JohnGarbutt JohnGarbutt Jun 17, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wonder if we can trim this list down somehow, it seems quite broad.

Lets get the full list from our test cluster of what we need to allow, and put that here, I think. Lets do a full sonaboy conformance test, and see what users we need in this allow list for that test to pass. Hopefully there are no arbitry ones 🤞

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sonobuoy fails trying to use its service account to create rolebindings in kube-system, but that's probably what we want?

Comment thread src/main.go
Comment thread src/main.go Outdated
Comment thread src/main_test.go
Comment thread src/main_test.go

@JohnGarbutt JohnGarbutt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks really close thank you.

My main worry is being stricter on the systemAccountRegex.

A few formatting nits, and also add go fmt into the the CI job please.

I think we should also move to a two stage docker build, something like:
https://docs.docker.com/build/building/multi-stage/#name-your-build-stages

Comment thread src/main.go Outdated
deniedLogOutput = "Allowed"
}
if logLevel >= 1 && sar.Spec.NonResourceAttributes != nil {
fmt.Printf("%s non-resource request from \"%s\". Reason: %s\n", deniedLogOutput, sar.Spec.User, status.Reason)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lets move this to the golang Log system, and try to use Println() to make sure they all go onto a new line:
https://pkg.go.dev/log

Its worth checking that we get what we expect to see inside Loki.

@JohnGarbutt JohnGarbutt Jun 17, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think the request has RemoteAddr (probably rubbish) and the Headers (e.g. X-Forwarded-For), which should tell us enough so we know which cluster has sent the request. Needs testing to see what works best inside Loki.

Key take away: be clear which cluster sent the request.

@JohnGarbutt JohnGarbutt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good work, thank you, lets cut a release with this in.

@wtripp180901
wtripp180901 merged commit 3070222 into main Jun 30, 2025
4 checks passed
@wtripp180901
wtripp180901 deleted the feat/system-users branch June 30, 2025 15:15
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.

2 participants