-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support generating cert based TLS type secret #10
Conversation
f9f7474
to
8532b05
Compare
4c001fb
to
0915f11
Compare
ae025e4
to
f8d590d
Compare
// Reset the resource version if the configmap or secret was unexpected deleted | ||
if existingConfigMap.Name == "" { | ||
reconciler.ProvidersReconcileState[req.NamespacedName].ConfigMapResourceVersion = nil | ||
} | ||
|
||
if provider.Spec.Secret == nil || existingSecret.Name == "" { |
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.
when spec.secret != nil
, it seems impossible that existingSecret.Name == ""
because of the line 145 . And what if there're multiple k8s secrets existing in cluster and some of them are deleted?
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.
Good catch! It should be updated accordingly
var secretType corev1.SecretType = corev1.SecretTypeOpaque | ||
var err error | ||
if secretTypeTag, ok := setting.Tags[PreservedSecretTypeTag]; ok { | ||
secretType, err = parseSecretType(secretTypeTag) |
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.
parseSecretType
looks like only supporting tls type? Can user set opaque type through tag?
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.
No, current I don't want to support it, if someone want an opaque secret, just don't set any tag
if err != nil { | ||
return nil, err | ||
} | ||
} else if csl.Spec.Secret == nil { |
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.
Does the else if
statement mean Spec.Secret
can be nil
when secret type is tls? If so, it may miss credentials when create SecretReferenceResolver
.
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.
Good catch, updated
@@ -141,8 +141,8 @@ type ManagedIdentityReferenceParameters struct { | |||
Key string `json:"key"` | |||
} | |||
|
|||
// AzureKeyVaultReference defines the authentication type used to Azure KeyVault resolve KeyVaultReference | |||
type AzureKeyVaultReference struct { | |||
// SecretReference defines the authentication type used to Azure KeyVault resolve KeyVaultReference |
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 description can be updated to match the latest usage. It contains more supported properties than auth.
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.
Updated
return true | ||
} | ||
} | ||
|
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.
Is it possible that the loop of updating secret in createOrUpdateSecrets
breaks early? ending up with a state that len(reconciler.ProvidersReconcileState[namespacedName].ExistingSecretReferences) == 0
is false and ExistingSecretReferences[name].SecretResourceVersion == secret.ResourceVersion
is true for all existing secrets, but the ir lengths don't match the length of settings.SecretSettings
hence needs reconcile.
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.
Updated. And moved this shouldReconcile()
function to processor
to make the detailed logic transparency to the controller.
|
||
if parsedType, ok := secretTypeMap[secretType]; ok { | ||
if parsedType != corev1.SecretTypeTLS { | ||
return "", fmt.Errorf("secret type %q is not supported", secretType) |
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.
So we don't allow customers to specify secretType opaque
via the preserved tag?
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 default Secret being generated is opaque
. There's no reasonable circumstance to specify opaque
as a preserved tag.
secret[k] = v | ||
} else if secret[k].Type != v.Type { | ||
return fmt.Errorf("secret type mismatch for key %q", k) | ||
|
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.
nit: extra empty line
internal/controller/processor.go
Outdated
RefreshOptions *RefreshOptions | ||
ResolveSecretReference loader.ResolveSecretReference | ||
ResolveSecretReference loader.SecretReferenceResolver |
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.
ResolveSecretReference
can be renamed to SecretReferenceResolver
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.
Updated
return false | ||
} | ||
|
||
if len(processor.ReconciliationState.ExistingSecretReferences) == 0 || |
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.
We can generate ConfigMap with empty data, Secret as well. When will len(processor.ReconciliationState.ExistingSecretReferences) == 0
and need to reconcile?
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.
Consider this scenario:
In beginning, no secret-related setting being specified in the yaml. Then user updates the yaml to add Secret. In this case, len(processor.ReconciliationState.ExistingSecretReferences) == 0
and need to reconcile
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.
If user updates the yaml, it can be returned early in line245. Does this scenario happen when user updates the yaml after seeing error log? Also there's a scenario when user specified secret
section in yaml but no key vault references in store, which may also make len(ExistingSecretReferences)==0
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.
Also there's a scenario when user specified secret section in yaml but no key vault references in store, which may also make len(ExistingSecretReferences)==0
No, as long as user specify the secret section, at least one secret will be generated even it's empty.
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.
I see, thanks
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.
If user updates the yaml, it can be returned early in line245.
Right, but len(processor.ReconciliationState.ExistingSecretReferences) == 0
is an unexpected scenario, once it happens means something was wrong(may be just because the reconciliation never succeeded)
default: | ||
err = fmt.Errorf("failed to get certificate, unknown content type '%s'", *resolvedSecret.ContentType) | ||
} | ||
} else { |
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.
if the else
statement deals with the situation when key vault reference is not backing certificate but with tls tag?
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.
I was looking into this part as well, no need to have the if..else..
block, just need to check the contentType and take relevant action.
339d54c
to
75317f8
Compare
a5b98c2
to
ef366bf
Compare
* Support generating cert based TLS type secret * Resolve comments * Resolve comments * Rename to SecretReferenceResolver * Add more test cases
Support generating cert-based TLS type secret