You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: make inline auth work in direct mode too (#520)
## Issue
Resolves#517.
## Description
The original implementation of inline auth only worked in continuous
mode because the code that sets env vars for the AWS SDK was in
`Reconcile` and was therefore not invoked by `Validate` (which direct
mode invokes). This fixes it by moving that code to `Validate` so that
it will run during direct mode too.
Also makes the following minor changes:
* Renames `accessKeyPair` in the YAML to `credentials` to match other
plugins and leave room for other credential related data.
* Removes code that reads values for the `AWS_SESSION_TOKEN` env var
from secrets and inline config and sets the env var for this. This env
var isn't meant to be manually set. Instead, a role is meant to be
assumed. Our spec already allows STS to be enabled and a role ARN to be
configured when it's enabled.
---------
Signed-off-by: Matt Welke <matt.welke@spectrocloud.com>
// configureAwsAuth sets environment variables to control AWS authentication. Order of precedence
115
-
// for source:
116
-
// 1 - Kubernetes secret
117
-
// 2 - Specified inline in spec
118
-
// Returns an error if env vars couldn't be set for any reason.
119
-
func (r*AwsValidatorReconciler) configureAwsAuth(auth v1alpha1.AwsAuth, reqNamespacestring, l logr.Logger) error {
113
+
// Checks whether the spec indicates that auth data should come from a k8s Secret instead of inline
114
+
// auth. If so, all data must come from the Secret. If any is missing, returns an error. If all data
115
+
// is present, overrides the data in the auth object.
116
+
func (r*AwsValidatorReconciler) authFromSecret(auth v1alpha1.AwsAuth, reqNamespacestring, l logr.Logger) (v1alpha1.AwsAuth, error) {
117
+
// If using implicit auth, there is no need to check for k8s Secrets.
120
118
ifauth.Implicit {
121
-
l.Info("auth.implicit set to true. Skipping setting AWS env vars.")
122
-
returnnil
119
+
l.Info("auth.implicit set to true. Skipping setting AWS_ env vars.")
120
+
returnauth, nil
123
121
}
124
122
125
-
ifauth.Credentials==nil {
126
-
auth.Credentials=&v1alpha1.Credentials{}
123
+
// Same if no secret name provided.
124
+
ifauth.SecretName=="" {
125
+
l.Info("No Secret name provided. Skipping looking for Secret to override auth data.")
126
+
returnauth, nil
127
127
}
128
128
129
-
// If Secret name provided, override any env var values with values from its data.
130
-
ifauth.SecretName!="" {
131
-
l.Info("auth.secretName provided. Using Secret as source for any AWS env vars defined in its data.", "secretName", auth.SecretName, "secretNamespace", reqNamespace)
l.Info("auth.secretName provided. Using Secret as source for any AWS_ env vars defined in its data.", "secretName", auth.SecretName, "secretNamespace", reqNamespace)
0 commit comments