From 8e0182aa503dbe2f9eb2cfb29a2bcf74ec400292 Mon Sep 17 00:00:00 2001 From: Rafael Date: Wed, 24 Dec 2025 19:03:50 -0300 Subject: [PATCH 1/5] FEAT: add TOTP support for change password and local build support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Pass TOTP code to DUC for Keycloak users with MFA - Add Dockerfile.local for local protospack builds - Add .dockerignore to exclude node_modules from Docker context 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .dockerignore | 12 ++++++++++++ Dockerfile.local | 14 ++++++++++++-- src/modules/auth/auth.controller.ts | 3 ++- src/modules/auth/auth.service.ts | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c9fc6a8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules +dist +.git +*.log +npm-debug.log* +.DS_Store +.env +.env.* +coverage +.nyc_output +*.tgz +!protospack.tgz diff --git a/Dockerfile.local b/Dockerfile.local index 03430e4..7f56186 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -1,4 +1,4 @@ -FROM node:20-alpine AS base_image +FROM node:22-alpine AS base_image RUN npm install -g npm@latest FROM base_image AS build_base @@ -19,10 +19,20 @@ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ # Local build with secrets +# Check if local protospack tarball exists (for local dev) FROM build_base AS build +COPY protospack*.tgz* ./ RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \ aws codeartifact login --tool npm --namespace @dadosfera --repository dadosfera-npm --domain dadosfera --domain-owner 611330257153 --region us-east-1 -RUN npm ci +RUN if [ -f "protospack.tgz" ]; then \ + echo "Installing from local protospack tarball..." && \ + npm install ./protospack.tgz --save-exact && \ + npm ci --ignore-scripts && \ + npm rebuild; \ + else \ + echo "Installing from CodeArtifact..." && \ + npm ci; \ + fi COPY . . RUN npm run build diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 3d86f14..3199fe3 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -190,13 +190,14 @@ export class AuthController { ) { this.logger.info('/auth - change-password'); - const { oldPassword, newPassword } = body; + const { oldPassword, newPassword, totpCode } = body; const { authorization: accessToken } = headers; return this.authClient.changePassword({ accessToken, oldPassword, newPassword, + totpCode, }); } diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index c1b85f6..6d67b95 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -143,6 +143,7 @@ export class AuthClientService implements OnModuleInit { accessToken, oldPassword, newPassword, + totpCode, }: AuthChangePasswordRequest) { this.logger.info('ChangePassword'); @@ -151,6 +152,7 @@ export class AuthClientService implements OnModuleInit { accessToken, oldPassword, newPassword, + totpCode, }), ); } From 52bda8ebe24519ad6d1ebf85793c3dc967e076a4 Mon Sep 17 00:00:00 2001 From: Rafael Date: Wed, 7 Jan 2026 18:55:36 -0300 Subject: [PATCH 2/5] FEAT: add authProvider field to user response - Add authProvider to user entity DTO - Update user service to include authProvider - Update auth controller response Co-Authored-By: Claude Opus 4.5 --- docsfera.json | 12 ++++-------- package-lock.json | 9 +++++---- package.json | 2 +- src/modules/auth/auth.controller.ts | 3 ++- src/modules/users/dtos/entities.ts | 2 ++ src/modules/users/users.service.ts | 1 + 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/docsfera.json b/docsfera.json index 572609f..8942a26 100644 --- a/docsfera.json +++ b/docsfera.json @@ -213,14 +213,7 @@ ], "responses": { "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "object" - } - } - } + "description": "" } }, "tags": [ @@ -8252,6 +8245,9 @@ "items": { "type": "string" } + }, + "authProvider": { + "type": "string" } }, "required": [ diff --git a/package-lock.json b/package-lock.json index e0de21d..c27510d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@aws-sdk/signature-v4": "^3.370.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "^3.38.0-beta.25", + "@dadosfera/protospack-v2": "^3.38.0-beta.26", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", @@ -1744,9 +1744,10 @@ } }, "node_modules/@dadosfera/protospack-v2": { - "version": "3.38.0-beta.25", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.38.0-beta.25.tgz", - "integrity": "sha512-OsOl9hJezmtWlVy+2vl3qbWP5yHmLktJ01r5aL475lcfKJtzFPZieUT9ES87C1Emrqe21E6IM/BkJK2rm/aUiA==", + "version": "3.38.0-beta.26", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.38.0-beta.26.tgz", + "integrity": "sha512-N8NS7+djLGy0wJXk00+4oupqd/wBIQ1f+YBBhK2y9x4guFXYK1KWIrPZhPj+gaU8g2KNkqKoT7SnE9PXNxlLSQ==", + "license": "ISC", "dependencies": { "@grpc/grpc-js": "^1.9.3", "rxjs": "^7.5.5" diff --git a/package.json b/package.json index fa47b52..4fd10bd 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@aws-sdk/signature-v4": "^3.370.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "^3.38.0-beta.25", + "@dadosfera/protospack-v2": "^3.38.0-beta.26", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 3199fe3..34dfd06 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -215,7 +215,8 @@ export class AuthController { const { username } = body; - return this.authClient.resetPassword({ username }, metadata); + await this.authClient.resetPassword({ username }, metadata); + return { authProvider: process.env.AUTH_PROVIDER || 'cognito' }; } @ApiInternalOnlyEndpoint() diff --git a/src/modules/users/dtos/entities.ts b/src/modules/users/dtos/entities.ts index ab5e43c..eef5ca0 100644 --- a/src/modules/users/dtos/entities.ts +++ b/src/modules/users/dtos/entities.ts @@ -64,6 +64,8 @@ export class UserNoRolesAndCustomer extends OmitType(UserNoRoles, [ export class IUserByCustomer extends OmitType(User, ['customer']) { @ApiPropertyOptional() permissions?: string[]; + @ApiPropertyOptional() + authProvider?: string; } export class CreateUserReq { diff --git a/src/modules/users/users.service.ts b/src/modules/users/users.service.ts index d402ff1..29ec0e3 100644 --- a/src/modules/users/users.service.ts +++ b/src/modules/users/users.service.ts @@ -125,6 +125,7 @@ export class UsersService implements OnModuleInit { return { permissions }; }); res.user.permissions = permissions; + res.user.authProvider = process.env.AUTH_PROVIDER || 'cognito'; return res; } From 3b8310fdca45be66a74d525752056be9641bc147 Mon Sep 17 00:00:00 2001 From: Rafael Date: Wed, 7 Jan 2026 19:04:07 -0300 Subject: [PATCH 3/5] CHORE: simplify Dockerfile.local to use npm ci only Remove protospack tarball fallback logic Co-Authored-By: Claude Opus 4.5 --- Dockerfile.local | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Dockerfile.local b/Dockerfile.local index 7f56186..fc8afaf 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -19,20 +19,10 @@ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ # Local build with secrets -# Check if local protospack tarball exists (for local dev) FROM build_base AS build -COPY protospack*.tgz* ./ RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \ aws codeartifact login --tool npm --namespace @dadosfera --repository dadosfera-npm --domain dadosfera --domain-owner 611330257153 --region us-east-1 -RUN if [ -f "protospack.tgz" ]; then \ - echo "Installing from local protospack tarball..." && \ - npm install ./protospack.tgz --save-exact && \ - npm ci --ignore-scripts && \ - npm rebuild; \ - else \ - echo "Installing from CodeArtifact..." && \ - npm ci; \ - fi +RUN npm ci COPY . . RUN npm run build From 1881d07c4a5d9ba71c45eb00d808f779cfcce1ed Mon Sep 17 00:00:00 2001 From: Rafael Date: Thu, 8 Jan 2026 12:10:17 -0300 Subject: [PATCH 4/5] FEAT: add dual auth provider support to Helm chart - Add auth_provider config to values.yaml (cognito/keycloak) - Add AUTH_PROVIDER env var to deployment template - Add conditional Keycloak env vars (URL, realm, client ID, secret) - Enables parallel deployments with different auth providers Co-Authored-By: Claude Opus 4.5 --- deploy/helm-chart/templates/deployment.yaml | 17 +++++++++++++++++ deploy/helm-chart/values.yaml | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/deploy/helm-chart/templates/deployment.yaml b/deploy/helm-chart/templates/deployment.yaml index 7312b30..fa44bc1 100644 --- a/deploy/helm-chart/templates/deployment.yaml +++ b/deploy/helm-chart/templates/deployment.yaml @@ -48,10 +48,27 @@ spec: {{- toYaml .Values.resources | nindent 12 }} {{- end }} env: + # Auth Provider Configuration + - name: AUTH_PROVIDER + value: {{ .Values.maestro.auth_provider | default "cognito" | quote }} - name: AWS_IDENTITY_POOL_ID value: {{ .Values.maestro.aws_identity_pool_id }} - name: AWS_REGION value: "us-east-1" + {{- if eq .Values.maestro.auth_provider "keycloak" }} + # Keycloak Configuration (when auth_provider=keycloak) + - name: KEYCLOAK_URL + value: {{ .Values.maestro.keycloak_url | quote }} + - name: KEYCLOAK_REALM + value: {{ .Values.maestro.keycloak_realm | default "dadosfera" | quote }} + - name: KEYCLOAK_CLIENT_ID + value: {{ .Values.maestro.keycloak_client_id | quote }} + - name: KEYCLOAK_CLIENT_SECRET + valueFrom: + secretKeyRef: + name: {{ .Values.maestro.keycloak_secret_name | default "maestro-keycloak-credentials" }} + key: client-secret + {{- end }} - name: BASE_HOST value: "maestro_prd" - name: BUCKET_CUSTOMER_CSV_ASSETS diff --git a/deploy/helm-chart/values.yaml b/deploy/helm-chart/values.yaml index 30af31e..8730481 100644 --- a/deploy/helm-chart/values.yaml +++ b/deploy/helm-chart/values.yaml @@ -27,7 +27,14 @@ resources: cpu: 2000m memory: 2Gi maestro: + # Auth provider: "cognito" (default) or "keycloak" + auth_provider: "cognito" aws_identity_pool_id: "us-east-1_Mrezsw9Sn" + # Keycloak config (when auth_provider=keycloak) + keycloak_url: "" + keycloak_realm: "dadosfera" + keycloak_client_id: "" + keycloak_secret_name: "maestro-keycloak-credentials" duc_url: duc.dadosfera.ai in_factory_url: in-factory.dadosfera.ai bucket_customer_csv_assets: "customers-csv-assets-prd-611330257153" From 8c34914806fc2e7d61cf94ea464e9d5c1342265d Mon Sep 17 00:00:00 2001 From: Rafael Date: Thu, 8 Jan 2026 12:13:59 -0300 Subject: [PATCH 5/5] FEAT: add AUTH_PROVIDER config to Helm chart - Add auth_provider to values.yaml (cognito/keycloak) - Add AUTH_PROVIDER env var to deployment template - Note: maestro only needs to know which provider is used, duc handles connection Co-Authored-By: Claude Opus 4.5 --- deploy/helm-chart/templates/deployment.yaml | 16 +--------------- deploy/helm-chart/values.yaml | 6 +----- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/deploy/helm-chart/templates/deployment.yaml b/deploy/helm-chart/templates/deployment.yaml index fa44bc1..dc8949d 100644 --- a/deploy/helm-chart/templates/deployment.yaml +++ b/deploy/helm-chart/templates/deployment.yaml @@ -48,27 +48,13 @@ spec: {{- toYaml .Values.resources | nindent 12 }} {{- end }} env: - # Auth Provider Configuration + # Auth Provider Configuration (cognito or keycloak) - name: AUTH_PROVIDER value: {{ .Values.maestro.auth_provider | default "cognito" | quote }} - name: AWS_IDENTITY_POOL_ID value: {{ .Values.maestro.aws_identity_pool_id }} - name: AWS_REGION value: "us-east-1" - {{- if eq .Values.maestro.auth_provider "keycloak" }} - # Keycloak Configuration (when auth_provider=keycloak) - - name: KEYCLOAK_URL - value: {{ .Values.maestro.keycloak_url | quote }} - - name: KEYCLOAK_REALM - value: {{ .Values.maestro.keycloak_realm | default "dadosfera" | quote }} - - name: KEYCLOAK_CLIENT_ID - value: {{ .Values.maestro.keycloak_client_id | quote }} - - name: KEYCLOAK_CLIENT_SECRET - valueFrom: - secretKeyRef: - name: {{ .Values.maestro.keycloak_secret_name | default "maestro-keycloak-credentials" }} - key: client-secret - {{- end }} - name: BASE_HOST value: "maestro_prd" - name: BUCKET_CUSTOMER_CSV_ASSETS diff --git a/deploy/helm-chart/values.yaml b/deploy/helm-chart/values.yaml index 8730481..37cd6be 100644 --- a/deploy/helm-chart/values.yaml +++ b/deploy/helm-chart/values.yaml @@ -28,13 +28,9 @@ resources: memory: 2Gi maestro: # Auth provider: "cognito" (default) or "keycloak" + # Note: maestro doesn't connect to Keycloak directly, only duc does auth_provider: "cognito" aws_identity_pool_id: "us-east-1_Mrezsw9Sn" - # Keycloak config (when auth_provider=keycloak) - keycloak_url: "" - keycloak_realm: "dadosfera" - keycloak_client_id: "" - keycloak_secret_name: "maestro-keycloak-credentials" duc_url: duc.dadosfera.ai in_factory_url: in-factory.dadosfera.ai bucket_customer_csv_assets: "customers-csv-assets-prd-611330257153"