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

Ensure Security Context Compliance in Tests and User-Scaffolded Tests for Restricted Environments #4423

Closed
camilamacedo86 opened this issue Dec 13, 2024 · 2 comments · Fixed by #4435
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@camilamacedo86
Copy link
Member

What do you want to happen?

Background

To ensure compliance with restricted environments, all Pods in our tests and test scaffolds must use a Security Context. This ensures that even when namespaces enforce strict security policies, the tests will pass, and the scaffolds users rely on will remain functional.

Currently:

  • The manager is configured by default to work in such environments.
  • However, in tests and test scaffolds, the curl Pod (used to verify metrics logs) lacks the necessary SecurityContext configuration.

Tasks

1. Namespace Labeling for Security Policy Enforcement

2. Secure curl Pod Configuration

  • Change the curl Pod creation command in testdata/project-v4/test/e2e/e2e_test.go#L209-L217 to include a proper SecurityContext. For example:

    cmd = exec.Command("kubectl", "run", curlPod,
        "--image=curlimages/curl:7.87.0", "-n", namespace,
        "--restart=Never",
        "--overrides", `{
            "spec": {
                "containers": [{
                    "name": "curl",
                    "image": "curlimages/curl:7.87.0",
                    "command": ["sh", "-c", "sleep 3600"],
                    "securityContext": {
                        "allowPrivilegeEscalation": false,
                        "capabilities": {
                            "drop": ["ALL"]
                        },
                        "runAsNonRoot": true,
                        "runAsUser": 1000,
                        "seccompProfile": {
                            "type": "RuntimeDefault"
                        }
                    }
                }],
                "serviceAccountName": "<project>-controller-manager"
            }
        }`)

3. Update e2e Test Framework

  • Modify e2e tests in test/e2e to ensure that all created Pods include a SecurityContext and are compatible with namespaces enforcing restricted security policies.

Expected Outcome

  • All e2e tests will pass in restricted environments with strict security contexts enforced.
  • User-scaffolded tests will include the necessary configurations to operate in restricted environments without requiring manual adjustments.

Additional Notes

Extra Labels

No response

@camilamacedo86 camilamacedo86 added kind/feature Categorizes issue or PR as related to a new feature. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. priority/backlog Higher priority than priority/awaiting-more-evidence. labels Dec 13, 2024
@lunarwhite
Copy link
Contributor

I'd like to take this one.

/assign

@lunarwhite
Copy link
Contributor

PR #4435 is ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants