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

IMN-521 authorization server #1086

Draft
wants to merge 88 commits into
base: IMN-521_authorization-server-part1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
e3e6ea3
Add api spec
taglioni-r Oct 11, 2024
8a99312
Merge branch 'IMN-794_authorization-platformstate-writer-v1' into IMN…
taglioni-r Oct 11, 2024
1266841
Merge branch 'IMN-794_authorization-platformstate-writer-v1' into IMN…
taglioni-r Oct 11, 2024
7784615
Draft
taglioni-r Oct 11, 2024
93616fe
Merge branch 'IMN-794_authorization-platformstate-writer-v1' into IMN…
taglioni-r Oct 11, 2024
691e730
Fix ConsumerKey
shuyec Oct 11, 2024
777d804
WIP
shuyec Oct 11, 2024
39a3937
Merge branch 'IMN-521_authorization-server' of https://github.com/pag…
shuyec Oct 11, 2024
5e74613
Fix ConsumerKey attributes
shuyec Oct 11, 2024
3fd3da4
Rename component state functions
shuyec Oct 11, 2024
32ae46c
Update config
taglioni-r Oct 14, 2024
9af7b99
Draft auditing logic
taglioni-r Oct 14, 2024
a25a4fa
Refactor
taglioni-r Oct 14, 2024
7b56ad5
Update config
taglioni-r Oct 14, 2024
c69f44b
Add errors placeholders
taglioni-r Oct 14, 2024
06f5ab6
Improve error handling
taglioni-r Oct 14, 2024
96faff6
Fix and refactor
taglioni-r Oct 15, 2024
9bfba41
Fix
taglioni-r Oct 15, 2024
06173f3
Add logic + update errors
shuyec Oct 16, 2024
4a6d28d
Fix Dockerfile
taglioni-r Oct 16, 2024
88bcbd0
Fix Dockerfile
taglioni-r Oct 16, 2024
4a1e0c0
Merge branch 'IMN-794_authorization-platformstate-writer-v1' into IMN…
shuyec Oct 16, 2024
43ea4a4
WIP
shuyec Oct 17, 2024
231a593
Update package.json
shuyec Oct 17, 2024
d46d310
Remove export for tokenService
shuyec Oct 17, 2024
b8892c4
Add authorization-server
shuyec Oct 17, 2024
43164f9
Create .env.test
shuyec Oct 17, 2024
49439e7
Add platformStateValidationFailed + JSON.stringify
shuyec Oct 17, 2024
97fa20b
Move audit types to models
shuyec Oct 17, 2024
3c4fa67
WIP
shuyec Oct 18, 2024
4bd7399
Add test
taglioni-r Oct 18, 2024
7c6497c
Add test
taglioni-r Oct 18, 2024
d2c2174
Temporarily skip test
taglioni-r Oct 18, 2024
18d1a8a
Simplify errors
taglioni-r Oct 18, 2024
768d341
Add test
taglioni-r Oct 18, 2024
0a8e392
Fix test name
taglioni-r Oct 18, 2024
5a84377
Add test
taglioni-r Oct 18, 2024
c39a8a5
Add util
taglioni-r Oct 18, 2024
70ba4a5
Add test
taglioni-r Oct 18, 2024
19d8c95
Add test
taglioni-r Oct 18, 2024
2dd8553
Simplify error
taglioni-r Oct 18, 2024
f93f075
Add test
taglioni-r Oct 18, 2024
6ca3b75
Update test util
taglioni-r Oct 18, 2024
a94b420
Add test
taglioni-r Oct 18, 2024
6586ea5
Remove test env
taglioni-r Oct 18, 2024
391a552
Update env
taglioni-r Oct 18, 2024
0940b33
Fix config
taglioni-r Oct 18, 2024
dfed0b1
Update test utils
taglioni-r Oct 18, 2024
447fa31
Add test
taglioni-r Oct 18, 2024
e060333
Simplify error
taglioni-r Oct 18, 2024
3d8b09e
Remove mock for uuid
taglioni-r Oct 18, 2024
d6e394f
Fix
taglioni-r Oct 18, 2024
1e982f3
Add test
taglioni-r Oct 18, 2024
b5aceeb
Simplify error message
taglioni-r Oct 21, 2024
10abd02
Work in progress
taglioni-r Oct 21, 2024
e56d7ac
Fix CI
taglioni-r Oct 21, 2024
33699ca
Merge branch 'IMN-794_authorization-platformstate-writer-v1' into IMN…
taglioni-r Oct 21, 2024
c96f208
Refactor
taglioni-r Oct 22, 2024
1e1f919
Refactor
taglioni-r Oct 22, 2024
22e3da7
Fix utils
taglioni-r Oct 22, 2024
55732fd
Add tests
taglioni-r Oct 22, 2024
b0a0939
Add test
taglioni-r Oct 22, 2024
b879cc9
Refactor
taglioni-r Oct 22, 2024
936f851
Revert "Refactor"
taglioni-r Oct 22, 2024
eb153b8
Merge branch 'authorization-server-refactor' into IMN-521_authorizati…
taglioni-r Oct 22, 2024
1d79c22
Revert refactor
taglioni-r Oct 22, 2024
9832270
Merge branch 'IMN-794_authorization-platformstate-writer-v1' into IMN…
taglioni-r Oct 23, 2024
fb96931
Improve tests
taglioni-r Oct 23, 2024
0dbfe3b
Remove only
taglioni-r Oct 23, 2024
b739162
Refactor
taglioni-r Oct 23, 2024
d09b1f6
Refactor
taglioni-r Oct 23, 2024
04347df
Refactor
taglioni-r Oct 23, 2024
64cbc88
Merge branch 'IMN-521_authorization-server-part1' into IMN-521_author…
taglioni-r Oct 24, 2024
63399ff
Remove unused dependencies
taglioni-r Oct 24, 2024
3dd4a77
Merge branch 'IMN-521_authorization-server' of https://github.com/pag…
taglioni-r Oct 24, 2024
fcee77e
Update pnpm-lock
taglioni-r Oct 24, 2024
de538ea
Merge branch 'IMN-521_authorization-server-part1' into IMN-521_author…
taglioni-r Oct 24, 2024
201f24b
Merge branch 'IMN-521_authorization-server-part1' into IMN-521_author…
taglioni-r Oct 24, 2024
fe726c7
Merge branch 'IMN-521_authorization-server-part1' into IMN-521_author…
taglioni-r Oct 24, 2024
4e22942
Fix correlationId
taglioni-r Oct 24, 2024
fcdc0e3
Minor refactor
taglioni-r Oct 24, 2024
dc9e8ea
Remove comment
taglioni-r Oct 24, 2024
b302510
Merge branch 'IMN-521_authorization-server-part1' into IMN-521_author…
taglioni-r Oct 24, 2024
b5d4285
Merge branch 'IMN-521_authorization-server-part1' into IMN-521_author…
taglioni-r Oct 25, 2024
14c17f6
Refactor
taglioni-r Oct 25, 2024
5397e02
Fix refactor
taglioni-r Oct 25, 2024
c9e25ef
Merge branch 'IMN-521_authorization-server-part1' into IMN-521_author…
taglioni-r Oct 25, 2024
387d958
Fix dates in token
taglioni-r Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"start:pn-consumers": "turbo start --filter pagopa-interop-pn-consumers",
"start:one-trust-notices": "turbo start --filter pagopa-interop-one-trust-notices",
"start:datalake-data-export": "turbo start --filter pagopa-interop-datalake-data-export",
"start:authorization-server": "turbo start --filter pagopa-interop-authorization-server",
"test": "turbo test",
"build": "turbo build",
"check": "turbo check",
Expand Down
215 changes: 215 additions & 0 deletions packages/api-clients/open-api/authorizationServerApi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
openapi: 3.0.3
info:
title: Interoperability Authorization Server Micro Service
description: Provides endpoints to request an interoperability token
version: "0.1.0"
contact:
name: API Support
url: "http://www.example.com/support"
email: [email protected]
termsOfService: "http://swagger.io/terms/"
x-api-id: an x-api-id
x-summary: an x-summary
servers:
- url: "/authorization-server"
description: Interoperability Authorization Server
tags:
- name: auth
description: Get security information
externalDocs:
description: Find out more
url: http://swagger.io
- name: health
description: Verify service status
externalDocs:
description: Find out more
url: http://swagger.io
paths:
"/token.oauth2":
post:
tags:
- auth
summary: Create a new access token
description: Return the generated access token
operationId: createToken
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
$ref: "#/components/schemas/AccessTokenRequest"
responses:
"200":
description: The Access token
headers:
Cache-Control:
schema:
type: string
default: no-cache, no-store
description: no-cache, no-store
"X-Rate-Limit-Limit":
schema:
type: integer
description: Max allowed requests within time interval
"X-Rate-Limit-Remaining":
schema:
type: integer
description: Remaining requests within time interval
"X-Rate-Limit-Interval":
schema:
type: integer
description: Time interval in milliseconds. Allowed requests will be constantly replenished during the interval. At the end of the interval the max allowed requests will be available
content:
application/json:
schema:
$ref: "#/components/schemas/ClientCredentialsResponse"
"400":
description: Bad request
x-noqa: RFC6749
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
"401":
description: Unauthorized
x-noqa: RFC6749
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
"429":
description: Too Many Requests
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
headers:
"X-Rate-Limit-Limit":
schema:
type: integer
description: Max allowed requests within time interval
"X-Rate-Limit-Remaining":
schema:
type: integer
description: Remaining requests within time interval
"X-Rate-Limit-Interval":
schema:
type: integer
description: Time interval in milliseconds. Allowed requests will be constantly replenished during the interval. At the end of the interval the max allowed requests will be available
/status:
get:
security: []
summary: Returns the application status
description: Returns the application status
operationId: get_status
tags:
- health
responses:
"200":
description: This is the valid status from the server.
content:
application/problem+json:
schema:
$ref: "#/components/schemas/Problem"
components:
schemas:
AccessTokenRequest:
type: object
required:
- client_assertion
- client_assertion_type
- grant_type
properties:
client_id:
type: string
example: e58035ce-c753-4f72-b613-46f8a17b71cc
client_assertion:
type: string
format: jws
client_assertion_type:
type: string
example: urn:ietf:params:oauth:client-assertion-type:jwt-bearer
grant_type:
type: string
enum:
- client_credentials
TokenType:
type: string
description: Represents the token type
enum:
- Bearer
ClientCredentialsResponse:
type: object
required:
- access_token
- token_type
- expires_in
properties:
access_token:
type: string
format: jws
token_type:
$ref: "#/components/schemas/TokenType"
expires_in:
type: integer
format: int32
maximum: 600
Problem:
properties:
type:
description: URI reference of type definition
type: string
status:
description: The HTTP status code generated by the origin server for this occurrence of the problem.
example: 400
exclusiveMaximum: true
format: int32
maximum: 600
minimum: 100
type: integer
title:
description: A short, summary of the problem type. Written in english and readable
example: Service Unavailable
maxLength: 64
pattern: "^[ -~]{0,64}$"
type: string
correlationId:
description: Unique identifier of the request
example: "53af4f2d-0c87-41ef-a645-b726a821852b"
maxLength: 64
type: string
detail:
description: A human readable explanation of the problem.
example: Request took too long to complete.
maxLength: 4096
pattern: "^.{0,1024}$"
type: string
errors:
type: array
minItems: 0
items:
$ref: "#/components/schemas/ProblemError"
additionalProperties: false
required:
- type
- status
- title
- errors
ProblemError:
properties:
code:
description: Internal code of the error
example: 123-4567
minLength: 8
maxLength: 8
pattern: "^[0-9]{3}-[0-9]{4}$"
type: string
detail:
description: A human readable explanation specific to this occurrence of the problem.
example: Parameter not valid
maxLength: 4096
pattern: "^.{0,1024}$"
type: string
required:
- code
- detail
1 change: 1 addition & 0 deletions packages/api-clients/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * as tenantApi from "./generated/tenantApi.js";
export * as apiGatewayApi from "./apiGatewayApi.js";
export * as notifierApi from "./generated/notifierApi.js";
export * from "./selfcareClients.js";
export * as authorizationServerApi from "./generated/authorizationServerApi.js";
45 changes: 45 additions & 0 deletions packages/authorization-server/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
HOST=0.0.0.0
PORT=3300
LOG_LEVEL=info

WELL_KNOWN_URLS="http://127.0.0.1:4500/jwks.json"
ACCEPTED_AUDIENCES="dev.interop.pagopa.it/ui,refactor.dev.interop.pagopa.it/ui,dev.interop.pagopa.it/m2m,refactor.dev.interop.pagopa.it/m2m"

# TODO: NOT SURE ABOUT THESE
AWS_CONFIG_FILE=aws.config.local
TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM="platform-states"
TOKEN_GENERATION_READMODEL_TABLE_NAME_TOKEN_GENERATION="token-generation-states"

AWS_REGION="eu-central-1"

CLIENT_ASSERTION_AUDIENCE="test.interop.pagopa.it"

GENERATED_INTEROP_TOKEN_ALGORITHM="RS256"
GENERATED_INTEROP_TOKEN_KID="test"
GENERATED_INTEROP_TOKEN_ISSUER="test"
GENERATED_INTEROP_TOKEN_M2M_AUDIENCE="test.interop.pagopa.it"
GENERATED_INTEROP_TOKEN_M2M_DURATION_SECONDS=60
# TODO: what's this supposed to be?
TOKEN_AUDITING_TOPIC="event-store.token.audit"

RATE_LIMITER_BURST_PERCENTAGE="0"
RATE_LIMITER_MAX_REQUESTS="10"
RATE_LIMITER_RATE_INTERVAL_MILLIS="1000"
RATE_LIMITER_REDIS_HOST="localhost"
RATE_LIMITER_REDIS_PORT="6379"
RATE_LIMITER_TIMEOUT_MILLIS="300"

PRODUCER_KAFKA_CLIENT_ID="authorization-server"
PRODUCER_KAFKA_BROKERS="localhost:9092"
PRODUCER_KAFKA_DISABLE_AWS_IAM_AUTH="true"

S3_BUCKET=interop-local-bucket
S3_CUSTOM_SERVER=true
S3_SERVER_HOST=http://localhost
S3_SERVER_PORT=9000

KAFKA_CLIENT_ID="authorization-server"
KAFKA_GROUP_ID="authorization-server-group"
KAFKA_BROKERS="localhost:9092"
KAFKA_DISABLE_AWS_IAM_AUTH="true"

50 changes: 50 additions & 0 deletions packages/authorization-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM node:20.14.0-slim@sha256:5e8ac65a0231d76a388683d07ca36a9769ab019a85d85169fe28e206f7a3208e as build

RUN corepack enable

WORKDIR /app
COPY package.json /app/
COPY pnpm-lock.yaml /app/
COPY pnpm-workspace.yaml /app/

COPY ./packages/authorization-server/package.json /app/packages/authorization-server/package.json
COPY ./packages/commons/package.json /app/packages/commons/package.json
COPY ./packages/models/package.json /app/packages/models/package.json
COPY ./packages/client-assertion-validation/package.json /app/packages/client-assertion-validation/package.json
COPY ./packages/kafka-iam-auth/package.json /app/packages/kafka-iam-auth/package.json
COPY ./packages/api-clients/package.json /app/packages/api-clients/package.json

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

COPY tsconfig.json /app/
COPY turbo.json /app/
COPY ./packages/authorization-server /app/packages/authorization-server
COPY ./packages/commons /app/packages/commons
COPY ./packages/models /app/packages/models
COPY ./packages/client-assertion-validation /app/packages/client-assertion-validation
COPY ./packages/kafka-iam-auth /app/packages/kafka-iam-auth
COPY ./packages/api-clients /app/packages/api-clients

RUN pnpm build && \
rm -rf /app/node_modules/.modules.yaml && \
rm -rf /app/node_modules/.cache && \
mkdir /out && \
cp -a --parents -t /out \
node_modules packages/authorization-server/node_modules \
package*.json packages/authorization-server/package*.json \
packages/commons/ \
packages/models/ \
packages/client-assertion-validation/ \
packages/kafka-iam-auth/ \
packages/api-clients \
packages/authorization-server/dist && \
find /out -exec touch -h --date=@0 {} \;

FROM node:20.14.0-slim@sha256:5e8ac65a0231d76a388683d07ca36a9769ab019a85d85169fe28e206f7a3208e as final

COPY --from=build /out /app

WORKDIR /app/packages/authorization-server
EXPOSE 3300

CMD [ "node", "." ]
12 changes: 12 additions & 0 deletions packages/authorization-server/aws.config.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[default]
aws_access_key_id=testawskey
aws_secret_access_key=testawssecret
region=eu-central-1
services=local

[services local]
dynamodb=
endpoint_url=http://localhost:8085

kms=
endpoint_url=http://localhost:4566
52 changes: 52 additions & 0 deletions packages/authorization-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "pagopa-interop-authorization-server",
"version": "1.0.0",
"description": "PagoPA Interoperability service for authorization",
"main": "dist",
"type": "module",
"scripts": {
"test": "vitest",
"lint": "eslint . --ext .ts,.tsx",
"lint:autofix": "eslint . --ext .ts,.tsx --fix",
"format:check": "prettier --check src",
"format:write": "prettier --write src",
"start": "node --loader ts-node/esm -r 'dotenv-flow/config' --watch ./src/index.ts",
"build": "tsc",
"check": "tsc --project tsconfig.check.json"
},
"keywords": [],
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@pagopa/eslint-config": "3.0.0",
"@protobuf-ts/runtime": "2.9.4",
"@types/node": "20.14.6",
"@types/uuid": "9.0.8",
"pagopa-interop-commons-test": "workspace:*",
"prettier": "2.8.8",
"ts-node": "10.9.2",
"typescript": "5.4.5",
"vitest": "1.6.0",
"uuid": "10.0.0",
"jose": "5.9.4"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "3.637.0",
"@aws-sdk/client-kms": "3.600.0",
"@aws-sdk/util-dynamodb": "3.637.0",
"@fastify/formbody": "8.0.1",
"@zodios/core": "10.9.6",
"axios": "1.7.4",
"connection-string": "4.4.0",
"dotenv-flow": "4.1.0",
"fastify": "5.0.0",
"kafka-iam-auth": "workspace:*",
"openapi-zod-client": "1.18.1",
"pagopa-interop-api-clients": "workspace:*",
"pagopa-interop-client-assertion-validation": "workspace:*",
"pagopa-interop-commons": "workspace:*",
"pagopa-interop-models": "workspace:*",
"ts-pattern": "5.2.0",
"zod": "3.23.8"
}
}
5 changes: 5 additions & 0 deletions packages/authorization-server/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import fastifyServer from "./routers/authorizationRouter.js";

const app = fastifyServer;

export default app;
Loading