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

Add new VaultAuthGlobal type #735

Merged
merged 7 commits into from
Jun 4, 2024

Conversation

benashz
Copy link
Collaborator

@benashz benashz commented May 9, 2024

The resource provide a resource holding Vault auth configuration that can be shared across VaultAuth resources. A VaultAuth instance only needs to provide the authentication method and a valid vaultAuthGlobalRef. VSO will automatically merge the VaultAuthGlobal with the referring VaultAuth. This allows for a VaultAuth instance to inherit some global authentication configuration.

The VaultAuthGlobal resource can be configured with one or more Vault auth method specific configuration.

Given the following VaultAuthGlobal:

apiVersion: secrets.hashicorp.com/v1beta1
kind: VaultAuthGlobal
metadata:
  name: default
  namespace: tenant-ns
spec:
  defaultAuthMethod: kubernetes
  kubernetes:
    audiences:
    - vault
    namespace: vault-tenant-ns
    mount: demo-auth-mount
    role: auth-role
    serviceAccount: default
    tokenExpirationSeconds: 600

The referring VaultAuth would look like:

apiVersion: secrets.hashicorp.com/v1beta1
kind: VaultAuth
metadata:
  name: default
  namespace: tenant-ns
spec:
  vaultAuthGlobalRef: default

If you wanted to override the kubernetes.role the VaultAuth would look like:

apiVersion: secrets.hashicorp.com/v1beta1
kind: VaultAuth
metadata:
  name: default
  namespace: tenant-ns
spec:
  vaultAuthGlobalRef: default
  kubernetes:
    role: other-auth-role

The referring VaultAuth's configuration always overrides its VaultAuthGlobal's configuration.

@benashz benashz force-pushed the VAULT-23381/add-support-global-vault-auth-config branch 2 times, most recently from 74dca96 to 7ecc7c0 Compare May 9, 2024 20:35
@benashz benashz force-pushed the VAULT-23381/add-support-global-vault-auth-config branch 5 times, most recently from 4406bf0 to 071ba35 Compare May 13, 2024 16:03
@benashz benashz added this to the v0.7.0 milestone May 13, 2024
@benashz benashz force-pushed the VAULT-23381/add-support-global-vault-auth-config branch 2 times, most recently from 303ce2f to 6eaec64 Compare May 13, 2024 19:07
@benashz
Copy link
Collaborator Author

benashz commented May 13, 2024

Relates to #341

@benashz benashz force-pushed the VAULT-23381/add-support-global-vault-auth-config branch from 6eaec64 to 84003e2 Compare May 14, 2024 11:55
@benashz benashz changed the title WIP: Add new VaultAuthGlobal type Add new VaultAuthGlobal type May 14, 2024
@benashz benashz force-pushed the VAULT-23381/add-support-global-vault-auth-config branch from 84003e2 to 86c22bc Compare May 14, 2024 14:00
The resource provide a resource holding Vault auth configuration that
can be shared across VaultAuth resources. A VaultAuth instance only
needs to provide the authentication method and a valid
vaultAuthGlobalRef. VSO will automatically merge the VaultAuthGlobal
with the referring VaultAuth. This allows for a VaultAuth instance to
inherit some global authentication configuration.

The VaultAuthGlobal resource can be configured with one or more Vault
auth method specific configuration.

Given the following VaultAuthGlobal:
```
apiVersion: secrets.hashicorp.com/v1beta1
kind: VaultAuthGlobal
metadata:
  name: default
  namespace: tenant-ns
spec:
  kubernetes:
    audiences:
    - vault
    namespace: demo-ns
    mount: demo-auth-mount
    role: auth-role
    serviceAccount: default
    tokenExpirationSeconds: 600
```

The referring VaultAuth would look like:
```
apiVersion: secrets.hashicorp.com/v1beta1
kind: VaultAuth
metadata:
  name: default
  namespace: tenant-ns
spec:
  method: kubernetes
  vaultAuthGlobalRef: default
```
@benashz benashz force-pushed the VAULT-23381/add-support-global-vault-auth-config branch from 86c22bc to b0a73a4 Compare May 14, 2024 15:13
@benashz benashz marked this pull request as ready for review May 14, 2024 16:43
@benashz benashz requested a review from a team as a code owner May 14, 2024 16:43
@benashz benashz requested review from tvoran and thyton May 15, 2024 13:05
Copy link
Member

@tvoran tvoran left a comment

Choose a reason for hiding this comment

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

This is looking good to me, my only real concern is that VaultConnectionRef in VaultAuthGlobal doesn't seem to be used.

api/v1beta1/vaultauth_types.go Outdated Show resolved Hide resolved
controllers/vaultauth_controller.go Outdated Show resolved Hide resolved
controllers/vaultauth_controller.go Outdated Show resolved Hide resolved
controllers/vaultauth_controller.go Outdated Show resolved Hide resolved
internal/common/common.go Show resolved Hide resolved
api/v1beta1/vaultauth_types.go Outdated Show resolved Hide resolved
Valid bool `json:"valid"`
Error string `json:"error"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
SpecHash string `json:"specHash,omitempty"`
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way for users to see what the merged VaultAuth spec is? I wonder if in the future putting the full merged spec in the status would make sense. Would be a a little crowded though.

Copy link
Collaborator Author

@benashz benashz May 17, 2024

Choose a reason for hiding this comment

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

It was definitely a consideration, since the hash of the spec is rather opaque :) I think it could make things easier to debug. I can spike in another PR to see what we think. Since we are introducing Conditions here, we could always extend it later as well.

controllers/vaultauth_controller.go Outdated Show resolved Hide resolved
controllers/vaultauth_controller.go Outdated Show resolved Hide resolved
api/v1beta1/vaultauthglobal_types.go Show resolved Hide resolved
Fixes:
- vaultConnectionRef not be inherited from the global auth
- firstNonZeroLen() always returned last
- misc doc updates and improvements
- some fixes to the credentials providers
Copy link
Contributor

@thyton thyton left a comment

Choose a reason for hiding this comment

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

It's looking good for me.

internal/common/common_test.go Show resolved Hide resolved
Copy link
Member

@tvoran tvoran left a comment

Choose a reason for hiding this comment

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

I'm not quite sure I understand the usage of conditions on the VaultAuth status, but this all seems to work for me.

api/v1beta1/vaultauthglobal_types.go Outdated Show resolved Hide resolved
Type: "VaultAuthGlobalRef",
Status: "True",
ObservedGeneration: o.Generation,
LastTransitionTime: metav1.NewTime(nowFunc()),
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem like a transition time, more like an evaluation time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we probably want the transition time to be related to whenever the ref was last updated.

var errs error

var conditions []metav1.Condition
Copy link
Member

Choose a reason for hiding this comment

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

Should this be adding onto the existing conditions on the object's status? It looks like this starts over with a single entry every evaluation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. I will address that in a follow-on PR.

Status: "True",
ObservedGeneration: o.Generation,
LastTransitionTime: metav1.NewTime(nowFunc()),
Reason: "VaultAuthGlobalRef",
Copy link
Member

@tvoran tvoran May 21, 2024

Choose a reason for hiding this comment

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

I wonder if Type and Reason should be different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Going to address this comment in a follow-on PR

@benashz benashz modified the milestones: v0.7.0, v0.8.0 May 22, 2024
@benashz benashz merged commit f8c1d88 into main Jun 4, 2024
38 checks passed
@benashz benashz deleted the VAULT-23381/add-support-global-vault-auth-config branch June 4, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow setting VaultAuth spec kubernetes mount as a default global setting
3 participants