From 68eb0f8dd9aef6c620cc821ad514cb40a0ab2720 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Fri, 15 Dec 2023 15:40:20 -0500 Subject: [PATCH 1/2] throw bad request when max uses reached --- backend/src/controllers/v1/universalAuthController.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/controllers/v1/universalAuthController.ts b/backend/src/controllers/v1/universalAuthController.ts index 65f59efbe3..0e88189854 100644 --- a/backend/src/controllers/v1/universalAuthController.ts +++ b/backend/src/controllers/v1/universalAuthController.ts @@ -129,9 +129,14 @@ export const renewAccessToken = async (req: Request, res: Response) => { accessTokenTTL, accessTokenLastRenewedAt, accessTokenMaxTTL, - createdAt: accessTokenCreatedAt + createdAt: accessTokenCreatedAt, + accessTokenNumUses, + accessTokenNumUsesLimit } = identityAccessToken; + if (accessTokenNumUses >= accessTokenNumUsesLimit) { + throw BadRequestError({ message: "Unable to renew because access token number of uses limit reached" }) + } // ttl check if (accessTokenTTL > 0) { From 1861dc85de28a7b8bd251b34c2bf3712e80f3756 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Mon, 18 Dec 2023 19:25:23 -0500 Subject: [PATCH 2/2] add crd owner --- helm-charts/secrets-operator/Chart.yaml | 2 +- k8-operator/controllers/infisicalsecret_helper.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/helm-charts/secrets-operator/Chart.yaml b/helm-charts/secrets-operator/Chart.yaml index 2a14d45d13..dcc1b1c70c 100644 --- a/helm-charts/secrets-operator/Chart.yaml +++ b/helm-charts/secrets-operator/Chart.yaml @@ -13,7 +13,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.3.2 +version: 0.3.3 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/k8-operator/controllers/infisicalsecret_helper.go b/k8-operator/controllers/infisicalsecret_helper.go index 2c291a46ee..5f7ff4798e 100644 --- a/k8-operator/controllers/infisicalsecret_helper.go +++ b/k8-operator/controllers/infisicalsecret_helper.go @@ -13,6 +13,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + ctrl "sigs.k8s.io/controller-runtime" ) const SERVICE_ACCOUNT_ACCESS_KEY = "serviceAccountAccessKey" @@ -159,7 +160,13 @@ func (r *InfisicalSecretReconciler) CreateInfisicalManagedKubeSecret(ctx context Data: plainProcessedSecrets, } - err := r.Client.Create(ctx, newKubeSecretInstance) + // Set InfisicalSecret instance as the owner and controller + err := ctrl.SetControllerReference(&infisicalSecret, newKubeSecretInstance, r.Scheme) + if err != nil { + return err + } + + err = r.Client.Create(ctx, newKubeSecretInstance) if err != nil { return fmt.Errorf("unable to create the managed Kubernetes secret : %w", err) }