-
Notifications
You must be signed in to change notification settings - Fork 7.4k
set auto-mount service account token to false in keycloak pods #40605
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
Open
KyriosGN0
wants to merge
4
commits into
keycloak:main
Choose a base branch
from
KyriosGN0:automount2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−6
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -301,6 +301,12 @@ private StatefulSet createBaseDeployment(Keycloak keycloakCR, Context<Keycloak> | |||||||||||||||||||||||||||||
if (!specBuilder.hasDnsPolicy()) { | ||||||||||||||||||||||||||||||
specBuilder.withDnsPolicy("ClusterFirst"); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if (Boolean.TRUE.equals(keycloakCR.getSpec().getAutomountServiceAccountToken()) || keycloakCR.getSpec().getAutomountServiceAccountToken() == null) { | ||||||||||||||||||||||||||||||
specBuilder.withAutomountServiceAccountToken(true); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
} else if (Boolean.FALSE.equals(keycloakCR.getSpec().getAutomountServiceAccountToken())) { | ||||||||||||||||||||||||||||||
specBuilder.withAutomountServiceAccountToken(false); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
handleScheduling(keycloakCR, schedulingLabels, specBuilder); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// there isn't currently an editOrNewFirstContainer, so we need to do this manually | ||||||||||||||||||||||||||||||
|
@@ -439,14 +445,18 @@ private void addEnvVars(StatefulSet baseDeployment, Keycloak keycloakCR, TreeSet | |||||||||||||||||||||||||||||
LinkedHashMap<String, EnvVar> varMap = Stream.concat(Stream.concat(env.stream(), firstClasssEnvVars.stream()), additionalEnvVars.stream()) | ||||||||||||||||||||||||||||||
.collect(Collectors.toMap(EnvVar::getName, Function.identity(), (e1, e2) -> e1, LinkedHashMap::new)); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
String truststores = SERVICE_ACCOUNT_DIR + "ca.crt"; | ||||||||||||||||||||||||||||||
String truststores = SERVICE_ACCOUNT_DIR; | ||||||||||||||||||||||||||||||
if (baseDeployment.getSpec().getTemplate().getSpec().getAutomountServiceAccountToken()) { | ||||||||||||||||||||||||||||||
truststores += "ca.crt"; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (useServiceCaCrt) { | ||||||||||||||||||||||||||||||
truststores += "," + SERVICE_CA_CRT; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// include the kube CA if the user is not controlling KC_TRUSTSTORE_PATHS via the unsupported or the additional | ||||||||||||||||||||||||||||||
varMap.putIfAbsent(KC_TRUSTSTORE_PATHS, new EnvVarBuilder().withName(KC_TRUSTSTORE_PATHS).withValue(truststores).build()); | ||||||||||||||||||||||||||||||
if (Boolean.TRUE.equals(baseDeployment.getSpec().getTemplate().getSpec().getAutomountServiceAccountToken()) || useServiceCaCrt) { | ||||||||||||||||||||||||||||||
// include the kube CA if the user is not controlling KC_TRUSTSTORE_PATHS via the unsupported or the additional | ||||||||||||||||||||||||||||||
varMap.putIfAbsent(KC_TRUSTSTORE_PATHS, new EnvVarBuilder().withName(KC_TRUSTSTORE_PATHS).withValue(truststores).build()); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+456
to
+459
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Switching to using the entire service account directory if automount is disabled doesn't seem like the right thing to do. How about updating the truststores only if automount is enabled. |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
setTracingEnvVars(keycloakCR, varMap); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
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
143 changes: 143 additions & 0 deletions
143
operator/src/test/resources/test-serialization-keycloak-cr-without-automount.yml
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,143 @@ | ||
apiVersion: k8s.keycloak.org/v2alpha1 | ||
kind: Keycloak | ||
metadata: | ||
name: test-serialization-kc | ||
spec: | ||
instances: 3 | ||
image: my-image | ||
automountServiceAccountToken: false | ||
additionalOptions: | ||
- name: key1 | ||
value: value1 | ||
- name: features | ||
value: docker | ||
db: | ||
vendor: vendor | ||
usernameSecret: | ||
name: usernameSecret | ||
key: usernameSecretKey | ||
passwordSecret: | ||
name: passwordSecret | ||
key: passwordSecretKey | ||
host: host | ||
database: database | ||
url: url | ||
port: 123 | ||
schema: schema | ||
poolInitialSize: 1 | ||
poolMinSize: 2 | ||
poolMaxSize: 3 | ||
ingress: | ||
enabled: false | ||
className: nginx | ||
annotations: | ||
myAnnotation: myValue | ||
anotherAnnotation: anotherValue | ||
readinessProbe: | ||
periodSeconds: 50 | ||
failureThreshold: 3 | ||
livenessProbe: | ||
periodSeconds: 60 | ||
failureThreshold: 1 | ||
startupProbe: | ||
periodSeconds: 40 | ||
failureThreshold: 2 | ||
networkPolicy: | ||
enabled: true | ||
http: | ||
- ipBlock: | ||
cidr: 172.17.0.0/16 | ||
except: | ||
- 172.17.1.0/24 | ||
- namespaceSelector: | ||
matchLabels: | ||
project: myproject | ||
- podSelector: | ||
matchLabels: | ||
role: frontend | ||
https: | ||
- ipBlock: | ||
cidr: 172.17.0.0/16 | ||
except: | ||
- 172.17.1.0/24 | ||
- namespaceSelector: | ||
matchLabels: | ||
project: myproject | ||
- podSelector: | ||
matchLabels: | ||
role: frontend | ||
management: | ||
- ipBlock: | ||
cidr: 172.17.0.0/16 | ||
except: | ||
- 172.17.1.0/24 | ||
- namespaceSelector: | ||
matchLabels: | ||
project: myproject | ||
- podSelector: | ||
matchLabels: | ||
role: frontend | ||
http: | ||
httpEnabled: true | ||
httpPort: 123 | ||
httpsPort: 456 | ||
tlsSecret: my-tls-secret | ||
hostname: | ||
hostname: my-hostname | ||
admin: my-admin-hostname | ||
adminUrl: https://www.my-admin-hostname.org:8448/something | ||
strict: true | ||
strictBackchannel: true | ||
backchannelDynamic: true | ||
cache: | ||
configMapFile: | ||
name: my-config-map | ||
key: file.xml | ||
features: | ||
enabled: | ||
- docker | ||
- authorization | ||
disabled: | ||
- admin | ||
- step-up-authentication | ||
transaction: | ||
xaEnabled: false | ||
tracing: | ||
enabled: true | ||
endpoint: http://my-tracing:4317 | ||
serviceName: my-best-keycloak | ||
protocol: http/protobuf | ||
samplerType: parentbased_traceidratio | ||
samplerRatio: 0.01 | ||
compression: gzip | ||
resourceAttributes: | ||
service.namespace: keycloak-namespace | ||
service.name: custom-service-name | ||
resources: | ||
requests: | ||
cpu: "500m" | ||
memory: "500M" | ||
limits: | ||
cpu: "2" | ||
memory: "1500M" | ||
proxy: | ||
headers: forwarded | ||
truststores: | ||
x: | ||
secret: | ||
name: my-secret | ||
httpManagement: | ||
port: 9003 | ||
bootstrapAdmin: | ||
user: | ||
secret: something | ||
service: | ||
secret: else | ||
update: | ||
strategy: Auto | ||
revision: 1 | ||
unsupported: | ||
podTemplate: | ||
metadata: | ||
labels: | ||
my-label: "foo" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assumption moving forward is that there will be no null case - we'll set the spec automountServiceAccountToken to true or false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing null to be the default handling would probably be best.