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

Flux compatibility - service account annotations #3030

Closed
chlunde opened this issue Apr 6, 2022 · 6 comments
Closed

Flux compatibility - service account annotations #3030

chlunde opened this issue Apr 6, 2022 · 6 comments
Labels
bug Something isn't working stale

Comments

@chlunde
Copy link
Contributor

chlunde commented Apr 6, 2022

What happened?

We sometimes see bursts of Unauthorized for calls from crossplane providers to the kubernetes apiserver. After some debugging we've found that the UID in the service account does not match the token on the file system. We noticed that the service account has a "fluxcd.io" annotation, even though it is not managed by flux. This is because crossplane copies all annotations from the ControllerConfig to the ServiceAccount object. This is probably required for ArgoCD, and it is used for IRSA in AWS.

But for flux, this does not work. We believe flux will consider this as a situation where a former Kustomization managed this object, and delete it as it is no longer managed. crossplane will quickly recreate it, but the token mounted in the container will for some time have the old UID and the API server will reject the requests. I'm not sure if this is a race condition in the kubelet when a token is rotated while a pod is created, or if it is simply not a supported way to rotate the tokens by deleting the service account while it is in use, but Kubernetes does recover from this situation after a while.

The specific annotation is "kustomize.toolkit.fluxcd.io/checksum": "3583e44b78adb421bd53fcb43edfcd5d39b287b8"

How can we reproduce it?

Flux-managed ControllerConfig, see above

Suggested fix

I think we should exclude annotations with keys fluxcd.io/ or prefix kustomize.toolkit.fluxcd.io/ when creating the deployment and serviceaccount in

s.Labels = cc.Labels
s.Annotations = cc.Annotations
d.Labels = cc.Labels
d.Annotations = cc.Annotations

We might also want to skip key kubectl.kubernetes.io/last-applied-configuration or prefix kubectl.kubernetes.io/ as it is fairly misleading to copy it.

Long term crossplane should probably implement "bring your own service account" instead (see issue #2295 etc)

What environment did it happen in?

Crossplane version: 1.6.3, EKS 1.21, flux 0.17

@chlunde chlunde added the bug Something isn't working label Apr 6, 2022
chlunde added a commit to chlunde/crossplane that referenced this issue Apr 6, 2022
…trollerConfig

Flux will garbage collect the ServiceAccount if we copy the flux
annotations from the ControllerConfig.

Background:

We sometimes see bursts of Unauthorized for calls from crossplane
providers to the kubernetes apiserver. After some debugging we've
found that the UID in the service account does not match the token on
the file system. We noticed that the service account has a "fluxcd.io"
annotation, even though it is not managed by flux. This is because
crossplane copies all annotations from the `ControllerConfig` to the
`ServiceAccount` object. This is probably required for ArgoCD, and it
is used for IRSA in AWS.

But for flux, this does not work. We believe flux will consider this
as a situation where a former `Kustomization` managed this object, and
delete it as it is no longer managed. crossplane will quickly recreate
it, but the token mounted in the container will for some time have the
old UID and the API server will reject the requests. I'm not sure if
this is a race condition in the kubelet when a token is rotated while
a pod is created, or if it is simply not a supported way to rotate the
tokens by deleting the service account while it is in use, but
Kubernetes does recover from this situation after a while.

Fixes crossplane#3030

Signed-off-by: Carl Henrik Lunde <[email protected]>
@chlunde
Copy link
Contributor Author

chlunde commented Apr 6, 2022

Workaround (thanks @haarchri): kustomize.toolkit.fluxcd.io/prune: disabled

@negz
Copy link
Member

negz commented Jun 2, 2022

Cross-linking to #2468

@github-actions
Copy link

github-actions bot commented Sep 1, 2022

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 7 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

@github-actions github-actions bot added stale and removed stale labels Sep 1, 2022
@github-actions
Copy link

github-actions bot commented Dec 6, 2022

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 7 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

@github-actions github-actions bot added the stale label Dec 6, 2022
@wwentland
Copy link
Contributor

/fresh This is still an issue that should be addressed. Hopefully we can get some related PRs merged soon.

@github-actions github-actions bot removed the stale label Dec 6, 2022
@github-actions
Copy link

github-actions bot commented Mar 7, 2023

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 7 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

@github-actions github-actions bot added the stale label Mar 7, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
3 participants