-
-
Notifications
You must be signed in to change notification settings - Fork 4
Use service scope for user-info-fetcher AD kerberos keytab #698
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74b821a
Use service scope for user-info-fetcher AD kerberos keytab
nightkr 63e223a
Add ad-user-info test suite that I apparently forgot to commit before
nightkr 3a74209
Changelog
nightkr 20d19d0
Ignore RUSTSEC-2025-0012 for now
nightkr c582dd2
Update ring to satisfy cargo deny
nightkr c493329
Don't use a podoverride for testing the service scope
nightkr 98b06e8
Formatting
nightkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: LimitRange | ||
| metadata: | ||
| name: limit-request-ratio | ||
| spec: | ||
| limits: | ||
| - type: "Container" | ||
| maxLimitRequestRatio: | ||
| cpu: 5 | ||
| memory: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| {% if test_scenario['values']['openshift'] == 'true' %} | ||
| # see https://github.com/stackabletech/issues/issues/566 | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| commands: | ||
| - script: kubectl patch namespace $NAMESPACE -p '{"metadata":{"labels":{"pod-security.kubernetes.io/enforce":"privileged"}}}' | ||
| timeout: 120 | ||
| {% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| {% if lookup('env', 'VECTOR_AGGREGATOR') %} | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: vector-aggregator-discovery | ||
| {% endif %} |
9 changes: 9 additions & 0 deletions
9
tests/templates/kuttl/ad-user-info/01-install-vector-aggregator-discovery-configmap.yaml.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| {% if lookup('env', 'VECTOR_AGGREGATOR') %} | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: vector-aggregator-discovery | ||
| data: | ||
| ADDRESS: {{ lookup('env', 'VECTOR_AGGREGATOR') }} | ||
| {% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| metadata: | ||
| name: install-opa | ||
| timeout: 300 | ||
| commands: | ||
| - script: kubectl -n $NAMESPACE wait --for=condition=available opaclusters.opa.stackable.tech/test-opa --timeout 301s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| commands: | ||
| - script: | | ||
| kubectl apply -n $NAMESPACE -f - <<EOF | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: test | ||
| labels: | ||
| opa.stackable.tech/bundle: "true" | ||
| data: | ||
| test.rego: | | ||
| package test | ||
|
|
||
| import data.stackable.opa.userinfo.v1 as userinfo | ||
|
|
||
| currentUserInfoByUsername := userinfo.userInfoByUsername(input.username) | ||
| currentUserInfoById := userinfo.userInfoById(input.id) | ||
| --- | ||
| apiVersion: opa.stackable.tech/v1alpha1 | ||
| kind: OpaCluster | ||
| metadata: | ||
| name: test-opa | ||
| spec: | ||
| image: | ||
| {% if test_scenario['values']['opa-latest'].find(",") > 0 %} | ||
| custom: "{{ test_scenario['values']['opa-latest'].split(',')[1] }}" | ||
| productVersion: "{{ test_scenario['values']['opa-latest'].split(',')[0] }}" | ||
| {% else %} | ||
| productVersion: "{{ test_scenario['values']['opa-latest'] }}" | ||
| {% endif %} | ||
| pullPolicy: IfNotPresent | ||
| clusterConfig: | ||
| userInfo: | ||
| backend: | ||
| experimentalActiveDirectory: | ||
| ldapServer: sble-addc.sble.test | ||
| baseDistinguishedName: DC=sble,DC=test | ||
| customAttributeMappings: | ||
| country: c | ||
| kerberosSecretClassName: kerberos-ad | ||
| tls: | ||
| verification: | ||
| server: | ||
| caCert: | ||
| secretClass: tls-ad | ||
| cache: # optional, enabled by default | ||
| entryTimeToLive: 60s # optional, defaults to 60s | ||
| {% if lookup('env', 'VECTOR_AGGREGATOR') %} | ||
| vectorAggregatorConfigMapName: vector-aggregator-discovery | ||
| {% endif %} | ||
| servers: | ||
| config: | ||
| logging: | ||
| enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }} | ||
| podOverrides: | ||
| spec: | ||
| volumes: | ||
| - name: kerberos | ||
| ephemeral: | ||
| volumeClaimTemplate: | ||
| metadata: | ||
| annotations: | ||
| secrets.stackable.tech/scope: service=opa | ||
| roleGroups: | ||
| default: {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| metadata: | ||
| name: test-regorule | ||
| timeout: 300 | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: StatefulSet | ||
| metadata: | ||
| name: test-regorule | ||
| status: | ||
| readyReplicas: 1 | ||
| replicas: 1 |
29 changes: 29 additions & 0 deletions
29
tests/templates/kuttl/ad-user-info/20-install-test-regorule.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: StatefulSet | ||
| metadata: | ||
| name: test-regorule | ||
| labels: | ||
| app: test-regorule | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: test-regorule | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: test-regorule | ||
| spec: | ||
| containers: | ||
| - name: test-regorule | ||
| image: docker.stackable.tech/stackable/testing-tools:0.2.0-stackable0.0.0-dev | ||
| stdin: true | ||
| tty: true | ||
| resources: | ||
| requests: | ||
| memory: "128Mi" | ||
| cpu: "512m" | ||
| limits: | ||
| memory: "128Mi" | ||
| cpu: "1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestAssert | ||
| metadata: | ||
| name: test-regorule | ||
| commands: | ||
| - script: kubectl exec -n $NAMESPACE test-regorule-0 -- python /tmp/test-regorule.py -u 'http://test-opa-server-default:8081/v1/data/test' |
5 changes: 5 additions & 0 deletions
5
tests/templates/kuttl/ad-user-info/30-prepare-test-regorule.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| apiVersion: kuttl.dev/v1beta1 | ||
| kind: TestStep | ||
| commands: | ||
| - script: kubectl cp -n $NAMESPACE ./test-regorule.py test-regorule-0:/tmp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env python | ||
| import requests | ||
| import argparse | ||
| import json | ||
|
|
||
| # todo: make the test more comprehensive to check customAttributes | ||
| users_and_groups = { | ||
| "[email protected]": ["CN=Superset Admins,CN=Users,DC=sble,DC=test", "CN=Domain Users,CN=Users,DC=sble,DC=test", "CN=Users,CN=Builtin,DC=sble,DC=test"], | ||
| "[email protected]": ["CN=Domain Users,CN=Users,DC=sble,DC=test", "CN=Users,CN=Builtin,DC=sble,DC=test"], | ||
| } | ||
|
|
||
|
|
||
| def assertions( | ||
| username, response, opa_attribute, expected_groups, expected_attributes={} | ||
| ): | ||
| assert "result" in response | ||
| result = response["result"] | ||
| print(result) | ||
| assert opa_attribute in result, f"expected {opa_attribute} in {result}" | ||
|
|
||
| # repeated the right hand side for better output on error | ||
| assert "customAttributes" in result[opa_attribute] | ||
| assert "groups" in result[opa_attribute] | ||
| assert "id" in result[opa_attribute] | ||
| assert "username" in result[opa_attribute] | ||
|
|
||
| # todo: split out group assertions | ||
| print(f"Testing for {username} in groups {expected_groups}") | ||
| groups = sorted(result[opa_attribute]["groups"]) | ||
| expected_groups = sorted(expected_groups) | ||
| assert groups == expected_groups, f"got {groups}, expected: {expected_groups}" | ||
|
|
||
| # todo: split out customAttribute assertions | ||
| print(f"Testing for {username} with customAttributes {expected_attributes}") | ||
| custom_attributes = result[opa_attribute]["customAttributes"] | ||
| assert ( | ||
| custom_attributes == expected_attributes | ||
| ), f"got {custom_attributes}, expected: {expected_attributes}" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| all_args = argparse.ArgumentParser() | ||
| all_args.add_argument("-u", "--url", required=True, help="OPA service url") | ||
| args = vars(all_args.parse_args()) | ||
| params = {"strict-builtin-errors": "true"} | ||
|
|
||
| def make_request(payload): | ||
| response = requests.post(args["url"], data=json.dumps(payload), params=params) | ||
| expected_status_code = 200 | ||
| assert ( | ||
| response.status_code == expected_status_code | ||
| ), f"got {response.status_code}, expected: {expected_status_code}" | ||
| return response.json() | ||
|
|
||
| for username, groups in users_and_groups.items(): | ||
| try: | ||
| # todo: try this out locally until it works | ||
| # url = 'http://test-opa-svc:8081/v1/data' | ||
| payload = {"input": {"username": username}} | ||
| response = make_request(payload) | ||
| assertions(username, response, "currentUserInfoByUsername", groups, {}) | ||
|
|
||
| # do the reverse lookup | ||
| user_id = response["result"]["currentUserInfoByUsername"]["id"] | ||
| payload = {"input": {"id": user_id}} | ||
| response = make_request(payload) | ||
| assertions(username, response, "currentUserInfoById", groups, {}) | ||
| except Exception as e: | ||
| print(f"exception: {e}") | ||
| if response is not None: | ||
| print(f"request body: {payload}") | ||
| print(f"response body: {response}") | ||
| raise e | ||
|
|
||
| print("Test successful!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.