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

m2m-oauth-server: Managing M2M OAuth Server Tokens #1350

Merged
merged 44 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fa5c86d
m2m-oauth-server: define RPC calls
jkralik Jul 16, 2024
80a24e6
implement mongodb
jkralik Jul 16, 2024
683915b
update swagger
jkralik Jul 16, 2024
a56992b
add time_to_live in ns
jkralik Jul 16, 2024
54c66f5
m2m-oauth-server supports grpc and http APIs
jkralik Jul 17, 2024
2ae5d65
store set index
jkralik Jul 18, 2024
2c52627
fix linter
jkralik Jul 18, 2024
3a708eb
set helm charts
jkralik Jul 18, 2024
e3d3a41
fix chart
jkralik Jul 18, 2024
653fb75
fix validator
jkralik Jul 18, 2024
6d3f793
cleanup
jkralik Jul 18, 2024
13248dc
fix ports in helm
jkralik Jul 18, 2024
8aa6342
fix deployment
jkralik Jul 18, 2024
dc8c871
use seconds instead of nanoseconds in token from grpc
jkralik Jul 18, 2024
8cb1d2a
fix sonarcloud issue
jkralik Jul 18, 2024
a4e12b5
add subject
jkralik Jul 18, 2024
a94e0d5
add subject
jkralik Jul 18, 2024
7c562da
fix crt
jkralik Jul 19, 2024
249005a
fix for CR
jkralik Jul 19, 2024
b2a1a29
fix sentence
jkralik Jul 19, 2024
43287b4
fix for CR 2
jkralik Jul 19, 2024
0c765b9
fix for CR3
jkralik Jul 22, 2024
915b39a
fix smells
jkralik Jul 23, 2024
1a746f6
fix after CR 4
jkralik Jul 23, 2024
b44161c
Refactor for m2m token validation
Danielius1922 Jul 23, 2024
5a9998d
security: check whether token is trusted after validation
Danielius1922 Jul 23, 2024
18a1ee8
Add token cache
Danielius1922 Jul 25, 2024
e6acb12
validator: add configuration and helm charts
Danielius1922 Jul 25, 2024
433b803
Ensure that for parallel token verification only a single requests is
Danielius1922 Jul 25, 2024
90f952a
Periodically clean-up token cache
Danielius1922 Jul 25, 2024
8d82170
Fix static analysis issues and add tests
Danielius1922 Jul 29, 2024
90e48fd
fix delete expired tokens from DB
jkralik Aug 3, 2024
7d6e5fa
rename BlacklistTokens to DeleteTokens
jkralik Aug 3, 2024
70fe7d8
fix call
jkralik Aug 3, 2024
830fbf6
use same name as is in proto for originalTokenClaims
jkralik Aug 4, 2024
7bdc26f
fixing m2m-oauth-server-blacklist-client (#1355)
jkralik Aug 6, 2024
3618bc8
Implement New UI for API Token Service (#1353)
PatrikMatiasko Aug 9, 2024
253197c
Merge branch 'main' into jkralik/feature/m2m-oauth-server-blacklist
jkralik Aug 9, 2024
92b716f
Sidebar visibility by service ( API TOKENS )
PatrikMatiasko Aug 9, 2024
a07f14d
Conditional routing
PatrikMatiasko Aug 10, 2024
9a4d853
Conditional routing
PatrikMatiasko Aug 10, 2024
7a474b1
Conditional routing
PatrikMatiasko Aug 10, 2024
803d5ed
helm - enable apiTokens
jkralik Aug 10, 2024
32adebe
update bundle
jkralik Aug 11, 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CERT_TOOL_SIGN_ALG ?= ECDSA-SHA256
CERT_TOOL_ELLIPTIC_CURVE ?= P256
CERT_TOOL_IMAGE = ghcr.io/plgd-dev/hub/cert-tool:vnext

SUBDIRS := bundle certificate-authority cloud2cloud-connector cloud2cloud-gateway coap-gateway grpc-gateway resource-aggregate resource-directory http-gateway identity-store snippet-service test/oauth-server tools/cert-tool
SUBDIRS := bundle certificate-authority cloud2cloud-connector cloud2cloud-gateway coap-gateway grpc-gateway resource-aggregate resource-directory http-gateway identity-store snippet-service m2m-oauth-server test/oauth-server tools/cert-tool
.PHONY: $(SUBDIRS) push proto/generate clean build test env mongo nats certificates hub-build http-gateway-www simulators

default: build
Expand Down
6 changes: 3 additions & 3 deletions charts/plgd-hub/templates/certificate-authority/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ data:
# 0s - means infinity
maxConnectionIdle: {{ .apis.grpc.keepAlive.maxConnectionIdle }}
# 0s - means infinity
maxConnectionAge: {{ .apis.grpc.keepAlive.maxConnectionIdle }}
maxConnectionAge: {{ .apis.grpc.keepAlive.maxConnectionAge }}
# 0s - means infinity
maxConnectionAgeGrace: {{ .apis.grpc.keepAlive.maxConnectionAgeGrace }}
time: {{ .apis.grpc.keepAlive.maxConnectionIdle }}
timeout: {{ .apis.grpc.keepAlive.maxConnectionIdle }}
time: {{ .apis.grpc.keepAlive.time }}
timeout: {{ .apis.grpc.keepAlive.timeout }}
tls:
{{- $tls := .apis.grpc.tls }}
{{- include "plgd-hub.internalCertificateConfig" (list $ $tls $cert ) | indent 8 }}
Expand Down
19 changes: 1 addition & 18 deletions charts/plgd-hub/templates/m2m-oauth-server/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{- end -}}

{{- define "plgd-hub.m2moauthserver.createServiceCertByCm" }}
{{- $serviceTls := .Values.m2moauthserver.apis.http.tls.certFile }}
{{- $serviceTls := .Values.m2moauthserver.apis.grpc.tls.certFile }}
{{- if $serviceTls }}
{{- printf "" -}}
{{- else }}
Expand Down Expand Up @@ -78,14 +78,6 @@ true
{{- end }}
{{- end }}

{{- define "plgd-hub.m2moauthserver.clientServiceSecretEnabled" -}}
{{- if or .Values.global.m2mOAuthServer.clientServiceSecret .Values.m2moauthserver.clientServiceSecret.enabled }}
true
{{- else }}
{{- printf "" }}
{{- end }}
{{- end }}

{{- define "plgd-hub.m2moauthserver.getPrivateKeyFile" -}}
{{- $privateKeyFile := .Values.m2moauthserver.oauthSigner.privateKeyFile }}
{{- if and (not $privateKeyFile) (include "plgd-hub.m2moauthserver.privateKeySecretEnabled" $) }}
Expand All @@ -94,15 +86,6 @@ true
{{- printf "%s" $privateKeyFile }}
{{- end -}}

{{- define "plgd-hub.m2moauthserver.getClientServiceSecretFile" -}}
{{- $file := "" }}
{{- if include "plgd-hub.m2moauthserver.clientServiceSecretEnabled" $ }}
{{- $file = printf "%s/%s" .Values.m2moauthserver.clientServiceSecret.mountPath .Values.m2moauthserver.clientServiceSecret.fileName }}
{{- end }}
{{- printf "%s" $file }}
{{- end -}}


{{- define "plgd-hub.m2moauthserver.enabled" -}}
{{- if and .Values.m2moauthserver.enabled (include "plgd-hub.m2moauthserver.privateKeySecretEnabled" .) }}
true
Expand Down
49 changes: 40 additions & 9 deletions charts/plgd-hub/templates/m2m-oauth-server/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if include "plgd-hub.m2moauthserver.enabled" . }}
{{- $oauthServerCertPath := "/certs" }}
{{- $cert := "/certs" }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -17,16 +17,49 @@ data:
encoderConfig:
timeEncoder: {{ .log.encoderConfig.timeEncoder }}
apis:
grpc:
address: {{ .apis.grpc.address | default (printf "0.0.0.0:%v" .port) | quote }}
sendMsgSize: {{ int64 .apis.grpc.sendMsgSize | default 4194304 }}
recvMsgSize: {{ int64 .apis.grpc.recvMsgSize | default 4194304 }}
enforcementPolicy:
minTime: {{ .apis.grpc.enforcementPolicy.minTime }}
permitWithoutStream: {{ .apis.grpc.enforcementPolicy.permitWithoutStream }}
keepAlive:
# 0s - means infinity
maxConnectionIdle: {{ .apis.grpc.keepAlive.maxConnectionIdle }}
# 0s - means infinity
maxConnectionAge: {{ .apis.grpc.keepAlive.maxConnectionAge }}
# 0s - means infinity
maxConnectionAgeGrace: {{ .apis.grpc.keepAlive.maxConnectionAgeGrace }}
time: {{ .apis.grpc.keepAlive.time }}
timeout: {{ .apis.grpc.keepAlive.timeout }}
tls:
{{- $tls := .apis.grpc.tls }}
{{- include "plgd-hub.internalCertificateConfig" (list $ $tls $cert ) | indent 8 }}
clientCertificateRequired: {{ .apis.grpc.tls.clientCertificateRequired }}
authorization:
{{- $authorization := .apis.grpc.authorization }}
{{- include "plgd-hub.authorizationConfig" (list $ $authorization "m2moauthserver.apis.grpc.authorization" $cert ) | indent 8 }}
http:
address: {{ .apis.http.address | default (printf "0.0.0.0:%v" .port) | quote }}
address: {{ .apis.http.address | default (printf "0.0.0.0:%v" .httpPort) | quote }}
readTimeout: {{ .apis.http.readTimeout }}
readHeaderTimeout: {{ .apis.http.readHeaderTimeout }}
writeTimeout: {{ .apis.http.writeTimeout }}
idleTimeout: {{ .apis.http.idleTimeout }}
tls:
{{- $tls := .apis.http.tls }}
{{- include "plgd-hub.internalCertificateConfig" (list $ $tls $oauthServerCertPath ) | indent 8 }}
clientCertificateRequired: {{ .apis.http.tls.clientCertificateRequired }}
clients:
storage:
cleanUpDeletedTokens: {{ .clients.storage.cleanUpDeletedTokens | quote }}
use: {{ include "plgd-hub.useDatabase" (list $ . .clients.storage.use) | quote }}
mongoDB:
uri: {{ include "plgd-hub.mongoDBUri" (list $ .clients.storage.mongoDB.uri ) | quote }}
database: {{ .clients.storage.mongoDB.database }}
maxPoolSize: {{ .clients.storage.mongoDB.maxPoolSize }}
maxConnIdleTime: {{ .clients.storage.mongoDB.maxConnIdleTime }}
tls:
{{- $mongoDbTls := .clients.storage.mongoDB.tls }}
{{- include "plgd-hub.internalCertificateConfig" (list $ $mongoDbTls $cert ) | indent 10 }}
useSystemCAPool: {{ .clients.storage.mongoDB.tls.useSystemCAPool }}
{{- include "plgd-hub.openTelemetryExporterConfig" (list $ $cert ) | nindent 6 }}
oauthSigner:
privateKeyFile: {{ include "plgd-hub.m2moauthserver.getPrivateKeyFile" $ }}
domain: {{ include "plgd-hub.m2moauthserver.ingressDomain" $ }}
Expand Down Expand Up @@ -69,7 +102,7 @@ data:
jwtPrivateKey:
enabled: {{ .jwtPrivateKey.enabled }}
authorization:
{{- $authorization := include "plgd-hub.basicAuthorizationConfig" (list $ .jwtPrivateKey.authorization (printf "m2moauthserver.oauthSigner.clients[%v].jwtPrivateKey.authorization" $idx) $oauthServerCertPath) | fromYaml }}
{{- $authorization := include "plgd-hub.basicAuthorizationConfig" (list $ .jwtPrivateKey.authorization (printf "m2moauthserver.oauthSigner.clients[%v].jwtPrivateKey.authorization" $idx) $cert) | fromYaml }}
{{- if $authorization.audience }}
audience: {{ $authorization.audience | quote }}
{{- end }}
Expand All @@ -84,7 +117,5 @@ data:
{{- end }}
{{- end }}
{{- end }}
clients:
{{- include "plgd-hub.openTelemetryExporterConfig" (list $ $oauthServerCertPath) | nindent 6 }}
{{- end }}
{{- end }}
17 changes: 6 additions & 11 deletions charts/plgd-hub/templates/m2m-oauth-server/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ spec:
- "--config"
- {{ printf "%s/%s" .Values.m2moauthserver.config.mountPath .Values.m2moauthserver.config.fileName | quote }}
ports:
- name: http
- name: grpc
containerPort: {{ .Values.m2moauthserver.port }}
protocol: TCP
- name: http
containerPort: {{ .Values.m2moauthserver.httpPort }}
protocol: TCP
{{- with .Values.m2moauthserver.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
Expand All @@ -78,6 +81,7 @@ spec:
- name: service-crt
mountPath: {{ $rdServiceCert }}
{{- end }}
{{- include "plgd-hub.extraCAPoolMount" (list . .Values.extraCAPool.authorization) | nindent 12 }}
{{- include "plgd-hub.extraCAPoolMount" (list . .Values.extraCAPool.internal) | nindent 12 }}
{{- with .Values.m2moauthserver.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
Expand All @@ -87,22 +91,12 @@ spec:
mountPath: {{ .Values.m2moauthserver.privateKey.mountPath }}
readOnly: true
{{- end }}
{{- if include "plgd-hub.m2moauthserver.clientServiceSecretEnabled" $ }}
- name: {{ .Values.m2moauthserver.clientServiceSecret.volume }}
mountPath: {{ .Values.m2moauthserver.clientServiceSecret.mountPath }}
readOnly: true
{{- end }}
volumes:
{{- if include "plgd-hub.m2moauthserver.privateKeySecretEnabled" $ }}
- name: {{ .Values.m2moauthserver.privateKey.volume }}
secret:
secretName: {{ .Values.m2moauthserver.privateKey.secretName }}
{{- end }}
{{- if include "plgd-hub.m2moauthserver.clientServiceSecretEnabled" $ }}
- name: {{ .Values.m2moauthserver.clientServiceSecret.volume }}
secret:
secretName: {{ .Values.m2moauthserver.clientServiceSecret.secretName }}
{{- end }}
- name: {{ .Values.m2moauthserver.config.volume }}
configMap:
name: {{ include "plgd-hub.m2moauthserver.configName" . }}
Expand All @@ -111,6 +105,7 @@ spec:
secret:
secretName: {{ include "plgd-hub.m2moauthserver.serviceCertName" . }}
{{- end }}
{{- include "plgd-hub.extraCAPoolVolume" (list . .Values.extraCAPool.authorization) | nindent 8 }}
{{- include "plgd-hub.extraCAPoolVolume" (list . .Values.extraCAPool.internal) | nindent 8 }}
{{- with .Values.m2moauthserver.extraVolumes }}
{{- toYaml . | nindent 8 }}
Expand Down
40 changes: 40 additions & 0 deletions charts/plgd-hub/templates/m2m-oauth-server/grpc-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if and (include "plgd-hub.m2moauthserver.enabled" .) .Values.m2moauthserver.ingress.grpc.enabled }}
{{- $fullname := include "plgd-hub.m2moauthserver.fullname" . }}
{{- $port := .Values.m2moauthserver.port }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullname }}-grpc
namespace: {{ .Release.Namespace }}
labels:
{{- include "plgd-hub.labels" . | nindent 4 }}
annotations:
{{- if .Values.m2moauthserver.ingress.grpc.annotations }}
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.ingress.grpc.annotations "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.m2moauthserver.ingress.grpc.customAnnotations }}
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.ingress.grpc.customAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
tls:
- hosts:
- {{ include "plgd-hub.m2moauthserver.ingressDomain" . | quote }}
{{- if $.Values.global.enableWildCartCert }}
secretName: {{ include "plgd-hub.wildCardCertName" . | quote }}
{{- else }}
secretName: {{ include "plgd-hub.m2moauthserver.domainCertName" . | quote }}
{{- end }}
rules:
- host: {{ include "plgd-hub.m2moauthserver.ingressDomain" . | quote }}
http:
paths:
{{- range .Values.m2moauthserver.ingress.grpc.paths }}
- path: {{ . }}
pathType: Prefix
backend:
service:
name: {{ $fullname }}-grpc
port:
number: {{ $port }}
{{- end }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/plgd-hub/templates/m2m-oauth-server/grpc-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if and (include "plgd-hub.m2moauthserver.enabled" .) }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "plgd-hub.m2moauthserver.fullname" . }}-grpc
namespace: {{ .Release.Namespace }}
labels:
{{- include "plgd-hub.labels" . | nindent 4 }}
{{- with .Values.m2moauthserver.service.grpc.labels }}
{{- . | toYaml | nindent 4 }}
{{- end }}
{{- if .Values.m2moauthserver.service.grpc.annotations }}
annotations:
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.service.grpc.annotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.m2moauthserver.service.grpc.type | default "ClusterIP" }}
ports:
- port: {{ .Values.m2moauthserver.port }}
targetPort: {{ .Values.m2moauthserver.service.grpc.targetPort }}
protocol: {{ .Values.m2moauthserver.service.grpc.protocol }}
name: {{ .Values.m2moauthserver.service.grpc.name }}
selector:
{{- include "plgd-hub.m2moauthserver.selectorLabels" . | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if and (include "plgd-hub.m2moauthserver.enabled" .) .Values.m2moauthserver.ingress.enabled }}
{{- if and (include "plgd-hub.m2moauthserver.enabled" .) .Values.m2moauthserver.ingress.http.enabled }}
{{- $fullname := include "plgd-hub.m2moauthserver.fullname" . }}
{{- $port := .Values.m2moauthserver.port }}
{{- $port := .Values.m2moauthserver.httpPort }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
Expand All @@ -9,11 +9,11 @@ metadata:
labels:
{{- include "plgd-hub.labels" . | nindent 4 }}
annotations:
{{- if .Values.m2moauthserver.ingress.annotations }}
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.ingress.annotations "context" $ ) | nindent 4 }}
{{- if .Values.m2moauthserver.ingress.http.annotations }}
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.ingress.http.annotations "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.m2moauthserver.ingress.customAnnotations }}
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.ingress.customAnnotations "context" $ ) | nindent 4 }}
{{- if .Values.m2moauthserver.ingress.http.customAnnotations }}
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.ingress.http.customAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
tls:
Expand All @@ -28,7 +28,7 @@ spec:
- host: {{ include "plgd-hub.m2moauthserver.ingressDomain" . | quote }}
http:
paths:
{{- range .Values.m2moauthserver.ingress.paths }}
{{- range .Values.m2moauthserver.ingress.http.paths }}
- path: {{ . }}
pathType: Prefix
backend:
Expand Down
25 changes: 25 additions & 0 deletions charts/plgd-hub/templates/m2m-oauth-server/http-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if include "plgd-hub.m2moauthserver.enabled" . -}}
apiVersion: v1
kind: Service
metadata:
name: {{ include "plgd-hub.m2moauthserver.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "plgd-hub.labels" . | nindent 4 }}
{{- with .Values.m2moauthserver.service.http.labels }}
{{- . | toYaml | nindent 4 }}
{{- end }}
{{- if .Values.m2moauthserver.service.http.annotations }}
annotations:
{{- include "plgd-hub.tplvalues.render" ( dict "value" .Values.m2moauthserver.service.http.annotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.m2moauthserver.service.http.type | default "ClusterIP" }}
ports:
- port: {{ .Values.m2moauthserver.httpPort }}
targetPort: {{ .Values.m2moauthserver.service.http.targetPort }}
protocol: {{ .Values.m2moauthserver.service.http.protocol }}
name: {{ .Values.m2moauthserver.service.http.name }}
selector:
{{- include "plgd-hub.m2moauthserver.selectorLabels" . | nindent 4 }}
{{- end }}
7 changes: 5 additions & 2 deletions charts/plgd-hub/templates/m2m-oauth-server/service-crt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ spec:
dnsNames:
- {{ printf "%s.%s.svc.%s" $serviceDns .Release.Namespace .Values.cluster.dns | quote }}
- {{ $serviceDns | quote }}
{{- if .Values.m2moauthserver.service.crt.extraDnsNames }}
{{- toYaml .Values.m2moauthserver.service.crt.extraDnsNames | nindent 4 }}
{{- if .Values.m2moauthserver.service.grpc.crt.extraDnsNames }}
{{- toYaml .Values.m2moauthserver.service.grpc.crt.extraDnsNames | nindent 4 }}
{{- end }}
{{- if .Values.m2moauthserver.service.http.crt.extraDnsNames }}
{{- toYaml .Values.m2moauthserver.service.http.crt.extraDnsNames | nindent 4 }}
{{- end }}
duration: {{ .Values.certmanager.internal.cert.duration | default .Values.certmanager.default.cert.duration }}
renewBefore: {{ .Values.certmanager.internal.cert.renewBefore | default .Values.certmanager.default.cert.renewBefore }}
Expand Down
25 changes: 0 additions & 25 deletions charts/plgd-hub/templates/m2m-oauth-server/service.yaml

This file was deleted.

Loading