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

Support generating cert based TLS type secret #10

Merged
merged 5 commits into from
Mar 4, 2024

Conversation

RichardChen820
Copy link
Contributor

Support generating cert-based TLS type secret

@RichardChen820 RichardChen820 force-pushed the user/junbchen/secretTypeSupport branch 2 times, most recently from f9f7474 to 8532b05 Compare January 30, 2024 12:34
@RichardChen820 RichardChen820 changed the base branch from main to release/v1.1 January 31, 2024 07:55
@RichardChen820 RichardChen820 changed the base branch from release/v1.1 to main January 31, 2024 07:56
@RichardChen820 RichardChen820 force-pushed the user/junbchen/secretTypeSupport branch 5 times, most recently from 4c001fb to 0915f11 Compare February 1, 2024 08:22
@RichardChen820 RichardChen820 marked this pull request as ready for review February 1, 2024 08:22
@RichardChen820 RichardChen820 force-pushed the user/junbchen/secretTypeSupport branch 4 times, most recently from ae025e4 to f8d590d Compare February 2, 2024 07:45
// 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 == "" {
Copy link
Contributor

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?

Copy link
Contributor Author

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

internal/controller/appconfigurationprovider_controller.go Outdated Show resolved Hide resolved
internal/controller/appconfigurationprovider_controller.go Outdated Show resolved Hide resolved
internal/controller/appconfigurationprovider_controller.go Outdated Show resolved Hide resolved
internal/loader/configuration_setting_loader.go Outdated Show resolved Hide resolved
internal/loader/configuration_setting_loader.go Outdated Show resolved Hide resolved
var secretType corev1.SecretType = corev1.SecretTypeOpaque
var err error
if secretTypeTag, ok := setting.Tags[PreservedSecretTypeTag]; ok {
secretType, err = parseSecretType(secretTypeTag)
Copy link
Contributor

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?

Copy link
Contributor Author

@RichardChen820 RichardChen820 Feb 2, 2024

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

return true
}
}

Copy link

@juniwang juniwang Feb 6, 2024

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.

Copy link
Contributor Author

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)
Copy link

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?

Copy link
Contributor Author

@RichardChen820 RichardChen820 Feb 19, 2024

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra empty line

RefreshOptions *RefreshOptions
ResolveSecretReference loader.ResolveSecretReference
ResolveSecretReference loader.SecretReferenceResolver
Copy link
Contributor

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

Copy link
Contributor Author

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 ||
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@linglingye001 linglingye001 Feb 20, 2024

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

Copy link
Contributor Author

@RichardChen820 RichardChen820 Feb 20, 2024

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks

Copy link
Contributor Author

@RichardChen820 RichardChen820 Feb 20, 2024

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@RichardChen820 RichardChen820 force-pushed the user/junbchen/secretTypeSupport branch 3 times, most recently from 339d54c to 75317f8 Compare February 21, 2024 03:04
@RichardChen820 RichardChen820 changed the base branch from main to release/v1 March 1, 2024 16:07
@RichardChen820 RichardChen820 changed the base branch from release/v1 to main March 1, 2024 16:08
@RichardChen820 RichardChen820 force-pushed the user/junbchen/secretTypeSupport branch from a5b98c2 to ef366bf Compare March 4, 2024 02:08
@RichardChen820 RichardChen820 changed the base branch from main to release/v1 March 4, 2024 02:10
@RichardChen820 RichardChen820 merged commit b3bc3b1 into release/v1 Mar 4, 2024
4 checks passed
@RichardChen820 RichardChen820 deleted the user/junbchen/secretTypeSupport branch March 4, 2024 02:29
RichardChen820 added a commit that referenced this pull request Apr 17, 2024
* Support generating cert based TLS type secret

* Resolve comments

* Resolve comments

* Rename to SecretReferenceResolver

* Add more test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants