@continuoussecuritytooling/keycloak-reporter 0.1.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ct.yaml +6 -0
- package/.github/CONTRIBUTING.md +48 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +34 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +25 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +35 -0
- package/.github/workflows/pipeline.yml +58 -8
- package/.github/workflows/release.yml +37 -0
- package/CHANGELOG.md +22 -0
- package/Dockerfile +4 -2
- package/README.md +49 -12
- package/charts/keycloak-reporter/.helmignore +23 -0
- package/charts/keycloak-reporter/Chart.yaml +28 -0
- package/charts/keycloak-reporter/README.md +51 -0
- package/charts/keycloak-reporter/templates/NOTES.txt +0 -0
- package/charts/keycloak-reporter/templates/_helpers.tpl +62 -0
- package/charts/keycloak-reporter/templates/cronjob.yaml +66 -0
- package/charts/keycloak-reporter/templates/pvc.yaml +15 -0
- package/charts/keycloak-reporter/templates/secret.yaml +14 -0
- package/charts/keycloak-reporter/templates/serviceaccount.yaml +12 -0
- package/charts/keycloak-reporter/values.yaml +78 -0
- package/cli.ts +55 -14
- package/config/schema.json +65 -0
- package/dist/cli.js +39 -14
- package/dist/cli.js.map +1 -1
- package/dist/config/schema.json +65 -0
- package/dist/index.js +3 -82
- package/dist/index.js.map +1 -1
- package/dist/lib/client.js +1 -1
- package/dist/lib/client.js.map +1 -1
- package/dist/lib/convert.js +0 -0
- package/dist/lib/convert.js.map +0 -0
- package/dist/lib/output.js +13 -1
- package/dist/lib/output.js.map +1 -1
- package/dist/lib/user.js +0 -0
- package/dist/lib/user.js.map +0 -0
- package/dist/src/cli.js +0 -0
- package/dist/src/cli.js.map +0 -0
- package/dist/src/config.js +57 -0
- package/dist/src/config.js.map +1 -0
- package/docker_entrypoint.sh +1 -1
- package/e2e/fixtures/config.json +5 -0
- package/e2e/spec/clients.js +5 -3
- package/e2e/spec/config.js +29 -0
- package/e2e/spec/users.js +5 -3
- package/e2e/spec/webhooks.js +9 -4
- package/index.ts +4 -125
- package/jest.config.js +0 -1
- package/lib/client.ts +4 -1
- package/lib/output.ts +14 -1
- package/lintconf.yaml +42 -0
- package/package.json +7 -6
- package/renovate.json +15 -13
- package/src/config.ts +69 -0
- package/dist/package.json +0 -56
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{{- $fullName := include "keycloak-reporter.fullname" . -}}
|
|
2
|
+
{{- if (.Values.keycloak.config.volumes).reports }}
|
|
3
|
+
apiVersion: v1
|
|
4
|
+
kind: PersistentVolumeClaim
|
|
5
|
+
metadata:
|
|
6
|
+
name: {{ $fullName }}-reports
|
|
7
|
+
annotations: {{ .Values.keycloak.config.volumes.reports.annotations }}
|
|
8
|
+
spec:
|
|
9
|
+
accessModes:
|
|
10
|
+
- ReadWriteMany
|
|
11
|
+
storageClassName: {{ .Values.keycloak.config.volumes.reports.storageClassName }}
|
|
12
|
+
resources:
|
|
13
|
+
requests:
|
|
14
|
+
storage: {{ .Values.keycloak.config.volumes.reports.volumeSize }}
|
|
15
|
+
{{- end }}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{{- $fullName := include "keycloak-reporter.fullname" . -}}
|
|
2
|
+
apiVersion: v1
|
|
3
|
+
kind: Secret
|
|
4
|
+
metadata:
|
|
5
|
+
name: {{ $fullName }}
|
|
6
|
+
stringData:
|
|
7
|
+
{{- range $k, $v := .Values.keycloak.config }}
|
|
8
|
+
{{- if $v}}
|
|
9
|
+
{{ $k }}: {{ $v }}
|
|
10
|
+
{{- end }}
|
|
11
|
+
{{- end }}
|
|
12
|
+
{{- if (.Values.keycloak.config.volumes).reports }}
|
|
13
|
+
reports: /app/reports
|
|
14
|
+
{{- end }}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{{- if .Values.serviceAccount.create -}}
|
|
2
|
+
apiVersion: v1
|
|
3
|
+
kind: ServiceAccount
|
|
4
|
+
metadata:
|
|
5
|
+
name: {{ include "keycloak-reporter.serviceAccountName" . }}
|
|
6
|
+
labels:
|
|
7
|
+
{{- include "keycloak-reporter.labels" . | nindent 4 }}
|
|
8
|
+
{{- with .Values.serviceAccount.annotations }}
|
|
9
|
+
annotations:
|
|
10
|
+
{{- toYaml . | nindent 4 }}
|
|
11
|
+
{{- end }}
|
|
12
|
+
{{- end }}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Default values for keycloak-reporter.
|
|
2
|
+
# This is a YAML-formatted file.
|
|
3
|
+
# Declare variables to be passed into your templates.
|
|
4
|
+
|
|
5
|
+
replicaCount: 1
|
|
6
|
+
|
|
7
|
+
image:
|
|
8
|
+
repository: continuoussecuritytooling/keycloak-reporting-cli
|
|
9
|
+
pullPolicy: IfNotPresent
|
|
10
|
+
# Overrides the image tag whose default is the chart appVersion.
|
|
11
|
+
tag: "latest"
|
|
12
|
+
|
|
13
|
+
imagePullSecrets: []
|
|
14
|
+
nameOverride: ""
|
|
15
|
+
fullnameOverride: ""
|
|
16
|
+
|
|
17
|
+
serviceAccount:
|
|
18
|
+
# Specifies whether a service account should be created
|
|
19
|
+
create: true
|
|
20
|
+
# Annotations to add to the service account
|
|
21
|
+
annotations: {}
|
|
22
|
+
# The name of the service account to use.
|
|
23
|
+
# If not set and create is true, a name is generated using the fullname template
|
|
24
|
+
name: ""
|
|
25
|
+
|
|
26
|
+
podAnnotations: {}
|
|
27
|
+
|
|
28
|
+
podSecurityContext: {}
|
|
29
|
+
# fsGroup: 2000
|
|
30
|
+
|
|
31
|
+
securityContext: {}
|
|
32
|
+
|
|
33
|
+
env: {}
|
|
34
|
+
# capabilities:
|
|
35
|
+
# drop:
|
|
36
|
+
# - ALL
|
|
37
|
+
# readOnlyRootFilesystem: true
|
|
38
|
+
# runAsNonRoot: true
|
|
39
|
+
# runAsUser: 1000
|
|
40
|
+
|
|
41
|
+
keycloak:
|
|
42
|
+
config:
|
|
43
|
+
url: ""
|
|
44
|
+
clientId: ""
|
|
45
|
+
clientSecret: ""
|
|
46
|
+
output: "webhook"
|
|
47
|
+
webhookType: ""
|
|
48
|
+
webhookUrl: ""
|
|
49
|
+
webhookMessage: ""
|
|
50
|
+
volumes:
|
|
51
|
+
reports: ""
|
|
52
|
+
|
|
53
|
+
cronjobs:
|
|
54
|
+
- name: clients
|
|
55
|
+
script: /app/index.js listClients
|
|
56
|
+
schedule: 0 0 1 */3 *
|
|
57
|
+
- name: users
|
|
58
|
+
script: /app/index.js listUsers
|
|
59
|
+
schedule: 0 0 1 */3 *
|
|
60
|
+
|
|
61
|
+
resources: {}
|
|
62
|
+
# We usually recommend not to specify default resources and to leave this as a conscious
|
|
63
|
+
# choice for the user. This also increases chances charts run on environments with little
|
|
64
|
+
# resources, such as Minikube. If you do want to specify resources, uncomment the following
|
|
65
|
+
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
|
|
66
|
+
# limits:
|
|
67
|
+
# cpu: 100m
|
|
68
|
+
# memory: 128Mi
|
|
69
|
+
# requests:
|
|
70
|
+
# cpu: 100m
|
|
71
|
+
# memory: 128Mi
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
nodeSelector: {}
|
|
75
|
+
|
|
76
|
+
tolerations: []
|
|
77
|
+
|
|
78
|
+
affinity: {}
|
package/cli.ts
CHANGED
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { writeFileSync } from 'node:fs';
|
|
4
|
+
import path from 'path';
|
|
3
5
|
import yargs from 'yargs/yargs';
|
|
4
6
|
import { hideBin } from 'yargs/helpers';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
listUsers,
|
|
9
|
+
listClients,
|
|
10
|
+
Options,
|
|
11
|
+
convertJSON2CSV,
|
|
12
|
+
post2Webhook,
|
|
13
|
+
} from './index.js';
|
|
14
|
+
import config from './src/config.js';
|
|
15
|
+
|
|
9
16
|
|
|
10
17
|
class WebhookConfig {
|
|
11
18
|
type: string;
|
|
12
19
|
url: string;
|
|
13
20
|
title: string;
|
|
14
|
-
|
|
21
|
+
message?: string;
|
|
22
|
+
constructor(type: string, url: string, title: string, message?: string) {
|
|
15
23
|
this.type = type;
|
|
16
24
|
this.url = url;
|
|
17
25
|
this.title = title;
|
|
26
|
+
this.message = message;
|
|
18
27
|
}
|
|
19
28
|
}
|
|
20
29
|
|
|
30
|
+
class ReportConfig {
|
|
31
|
+
name: string;
|
|
32
|
+
directory: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
21
35
|
async function convert(
|
|
22
36
|
format: string,
|
|
23
37
|
output: string,
|
|
38
|
+
reports: ReportConfig,
|
|
24
39
|
config: WebhookConfig,
|
|
25
40
|
json: object
|
|
26
41
|
) {
|
|
@@ -33,6 +48,10 @@ async function convert(
|
|
|
33
48
|
default:
|
|
34
49
|
outputContent = JSON.stringify(json);
|
|
35
50
|
}
|
|
51
|
+
if (reports.directory) {
|
|
52
|
+
const date = new Date();
|
|
53
|
+
writeFileSync(path.join(`${reports.directory}`,`${reports.name}_${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}.${format.toLowerCase()}`), outputContent);
|
|
54
|
+
}
|
|
36
55
|
switch (output) {
|
|
37
56
|
case 'webhook':
|
|
38
57
|
try {
|
|
@@ -40,10 +59,12 @@ async function convert(
|
|
|
40
59
|
config.type,
|
|
41
60
|
config.url,
|
|
42
61
|
config.title,
|
|
43
|
-
outputContent
|
|
62
|
+
outputContent,
|
|
63
|
+
config.message,
|
|
44
64
|
);
|
|
45
65
|
} catch (e) {
|
|
46
66
|
console.error('Error during sending webhook: ', e);
|
|
67
|
+
throw e;
|
|
47
68
|
}
|
|
48
69
|
break;
|
|
49
70
|
// defaulting to standard out
|
|
@@ -60,17 +81,22 @@ yargs(hideBin(process.argv))
|
|
|
60
81
|
() => {},
|
|
61
82
|
async (argv) => {
|
|
62
83
|
const users = await listUsers(<Options>{
|
|
63
|
-
clientId: argv.clientId as string,
|
|
64
|
-
clientSecret: argv.clientSecret as string,
|
|
65
|
-
rootUrl: argv.url as string,
|
|
84
|
+
clientId: argv.clientId ? argv.clientId as string: config.clientId,
|
|
85
|
+
clientSecret: argv.clientSecret ? argv.clientSecret as string: config.clientSecret,
|
|
86
|
+
rootUrl:argv.url ? argv.url as string: config.url,
|
|
66
87
|
});
|
|
67
88
|
await convert(
|
|
68
89
|
argv.format as string,
|
|
69
90
|
argv.output as string,
|
|
91
|
+
{
|
|
92
|
+
name: 'user_listing',
|
|
93
|
+
directory: argv.reports as string,
|
|
94
|
+
},
|
|
70
95
|
new WebhookConfig(
|
|
71
96
|
argv.webhookType as string,
|
|
72
97
|
argv.webhookUrl as string,
|
|
73
|
-
'User Listing'
|
|
98
|
+
'User Listing',
|
|
99
|
+
argv.webhookMessage ? argv.webhookMessage as string: config.webhookMessage
|
|
74
100
|
),
|
|
75
101
|
users
|
|
76
102
|
);
|
|
@@ -83,17 +109,22 @@ yargs(hideBin(process.argv))
|
|
|
83
109
|
() => {},
|
|
84
110
|
async (argv) => {
|
|
85
111
|
const clients = await listClients(<Options>{
|
|
86
|
-
clientId: argv.clientId as string,
|
|
87
|
-
clientSecret: argv.clientSecret as string,
|
|
88
|
-
rootUrl: argv.url as string,
|
|
112
|
+
clientId: argv.clientId ? argv.clientId as string: config.clientId,
|
|
113
|
+
clientSecret: argv.clientSecret ? argv.clientSecret as string: config.clientSecret,
|
|
114
|
+
rootUrl:argv.url ? argv.url as string: config.url,
|
|
89
115
|
});
|
|
90
116
|
await convert(
|
|
91
117
|
argv.format as string,
|
|
92
118
|
argv.output as string,
|
|
119
|
+
{
|
|
120
|
+
name: 'client_listing',
|
|
121
|
+
directory: argv.reports as string,
|
|
122
|
+
},
|
|
93
123
|
new WebhookConfig(
|
|
94
124
|
argv.webhookType as string,
|
|
95
125
|
argv.webhookUrl as string,
|
|
96
|
-
'Client Listing'
|
|
126
|
+
'Client Listing',
|
|
127
|
+
argv.webhookMessage ? argv.webhookMessage as string: config.webhookMessage
|
|
97
128
|
),
|
|
98
129
|
clients
|
|
99
130
|
);
|
|
@@ -117,9 +148,19 @@ yargs(hideBin(process.argv))
|
|
|
117
148
|
default: 'slack',
|
|
118
149
|
description: 'Webhook Type',
|
|
119
150
|
})
|
|
151
|
+
.option('webhookMessage', {
|
|
152
|
+
alias: 'm',
|
|
153
|
+
type: 'string',
|
|
154
|
+
description: 'Webhook Message',
|
|
155
|
+
})
|
|
120
156
|
.option('webhookUrl', {
|
|
121
157
|
alias: 't',
|
|
122
158
|
type: 'string',
|
|
123
159
|
description: 'Webhook URL',
|
|
124
160
|
})
|
|
161
|
+
.option('reports', {
|
|
162
|
+
alias: 'r',
|
|
163
|
+
type: 'string',
|
|
164
|
+
description: 'Reports directory',
|
|
165
|
+
})
|
|
125
166
|
.parse();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "https://github.com/ContinuousSecurityTooling/keycloak-reporter/blob/main/config/schema.json",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"title": "Keycloak Reporter Config",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"definitions": {},
|
|
7
|
+
"required": ["url", "clientId", "clientSecret"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"command": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"items": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"enum": ["listClients", "listUsers"]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"url": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Keycloak Server URL"
|
|
19
|
+
},
|
|
20
|
+
"clientId": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Keycloak Client used for reporting"
|
|
23
|
+
},
|
|
24
|
+
"clientSecret": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Keycloak Client Secret used for reporting"
|
|
27
|
+
},
|
|
28
|
+
"output": {
|
|
29
|
+
"type": "array",
|
|
30
|
+
"items": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"enum": ["webhook", "stdout"]
|
|
33
|
+
},
|
|
34
|
+
"description": "Output channel to use"
|
|
35
|
+
},
|
|
36
|
+
"format": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"items": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"enum": ["json", "csv"]
|
|
41
|
+
},
|
|
42
|
+
"description": "Report format"
|
|
43
|
+
},
|
|
44
|
+
"webhookType": {
|
|
45
|
+
"type": "array",
|
|
46
|
+
"items": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"enum": ["slack", "teams"]
|
|
49
|
+
},
|
|
50
|
+
"description": "Type of webhook"
|
|
51
|
+
},
|
|
52
|
+
"webhookMessage": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"description": "Message added to the webhook post"
|
|
55
|
+
},
|
|
56
|
+
"webhookUrl": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"description": "URL of the webhook"
|
|
59
|
+
},
|
|
60
|
+
"reports": {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"description": "Reports directory"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'path';
|
|
2
4
|
import yargs from 'yargs/yargs';
|
|
3
5
|
import { hideBin } from 'yargs/helpers';
|
|
4
|
-
import { listUsers, listClients } from './
|
|
5
|
-
import
|
|
6
|
-
import { post2Webhook } from './lib/output.js';
|
|
6
|
+
import { listUsers, listClients, convertJSON2CSV, post2Webhook, } from './index.js';
|
|
7
|
+
import config from './src/config.js';
|
|
7
8
|
class WebhookConfig {
|
|
8
|
-
constructor(type, url, title) {
|
|
9
|
+
constructor(type, url, title, message) {
|
|
9
10
|
this.type = type;
|
|
10
11
|
this.url = url;
|
|
11
12
|
this.title = title;
|
|
13
|
+
this.message = message;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
class ReportConfig {
|
|
17
|
+
}
|
|
18
|
+
async function convert(format, output, reports, config, json) {
|
|
15
19
|
let outputContent;
|
|
16
20
|
switch (format) {
|
|
17
21
|
case 'csv':
|
|
@@ -21,13 +25,18 @@ async function convert(format, output, config, json) {
|
|
|
21
25
|
default:
|
|
22
26
|
outputContent = JSON.stringify(json);
|
|
23
27
|
}
|
|
28
|
+
if (reports.directory) {
|
|
29
|
+
const date = new Date();
|
|
30
|
+
writeFileSync(path.join(`${reports.directory}`, `${reports.name}_${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}.${format.toLowerCase()}`), outputContent);
|
|
31
|
+
}
|
|
24
32
|
switch (output) {
|
|
25
33
|
case 'webhook':
|
|
26
34
|
try {
|
|
27
|
-
await post2Webhook(config.type, config.url, config.title, outputContent);
|
|
35
|
+
await post2Webhook(config.type, config.url, config.title, outputContent, config.message);
|
|
28
36
|
}
|
|
29
37
|
catch (e) {
|
|
30
38
|
console.error('Error during sending webhook: ', e);
|
|
39
|
+
throw e;
|
|
31
40
|
}
|
|
32
41
|
break;
|
|
33
42
|
// defaulting to standard out
|
|
@@ -40,21 +49,27 @@ yargs(hideBin(process.argv))
|
|
|
40
49
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
41
50
|
() => { }, async (argv) => {
|
|
42
51
|
const users = await listUsers({
|
|
43
|
-
clientId: argv.clientId,
|
|
44
|
-
clientSecret: argv.clientSecret,
|
|
45
|
-
rootUrl: argv.url,
|
|
52
|
+
clientId: argv.clientId ? argv.clientId : config.clientId,
|
|
53
|
+
clientSecret: argv.clientSecret ? argv.clientSecret : config.clientSecret,
|
|
54
|
+
rootUrl: argv.url ? argv.url : config.url,
|
|
46
55
|
});
|
|
47
|
-
await convert(argv.format, argv.output,
|
|
56
|
+
await convert(argv.format, argv.output, {
|
|
57
|
+
name: 'user_listing',
|
|
58
|
+
directory: argv.reports,
|
|
59
|
+
}, new WebhookConfig(argv.webhookType, argv.webhookUrl, 'User Listing', argv.webhookMessage ? argv.webhookMessage : config.webhookMessage), users);
|
|
48
60
|
})
|
|
49
61
|
.command('listClients [url] [clientId] [clientSecret]', 'fetches all clients in the realms.',
|
|
50
62
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
51
63
|
() => { }, async (argv) => {
|
|
52
64
|
const clients = await listClients({
|
|
53
|
-
clientId: argv.clientId,
|
|
54
|
-
clientSecret: argv.clientSecret,
|
|
55
|
-
rootUrl: argv.url,
|
|
65
|
+
clientId: argv.clientId ? argv.clientId : config.clientId,
|
|
66
|
+
clientSecret: argv.clientSecret ? argv.clientSecret : config.clientSecret,
|
|
67
|
+
rootUrl: argv.url ? argv.url : config.url,
|
|
56
68
|
});
|
|
57
|
-
await convert(argv.format, argv.output,
|
|
69
|
+
await convert(argv.format, argv.output, {
|
|
70
|
+
name: 'client_listing',
|
|
71
|
+
directory: argv.reports,
|
|
72
|
+
}, new WebhookConfig(argv.webhookType, argv.webhookUrl, 'Client Listing', argv.webhookMessage ? argv.webhookMessage : config.webhookMessage), clients);
|
|
58
73
|
})
|
|
59
74
|
.option('format', {
|
|
60
75
|
alias: 'f',
|
|
@@ -73,11 +88,21 @@ yargs(hideBin(process.argv))
|
|
|
73
88
|
type: 'string',
|
|
74
89
|
default: 'slack',
|
|
75
90
|
description: 'Webhook Type',
|
|
91
|
+
})
|
|
92
|
+
.option('webhookMessage', {
|
|
93
|
+
alias: 'm',
|
|
94
|
+
type: 'string',
|
|
95
|
+
description: 'Webhook Message',
|
|
76
96
|
})
|
|
77
97
|
.option('webhookUrl', {
|
|
78
98
|
alias: 't',
|
|
79
99
|
type: 'string',
|
|
80
100
|
description: 'Webhook URL',
|
|
101
|
+
})
|
|
102
|
+
.option('reports', {
|
|
103
|
+
alias: 'r',
|
|
104
|
+
type: 'string',
|
|
105
|
+
description: 'Reports directory',
|
|
81
106
|
})
|
|
82
107
|
.parse();
|
|
83
108
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,SAAS,EACT,WAAW,EAEX,eAAe,EACf,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAGrC,MAAM,aAAa;IAKjB,YAAY,IAAY,EAAE,GAAW,EAAE,KAAa,EAAE,OAAgB;QACpE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,MAAM,YAAY;CAGjB;AAED,KAAK,UAAU,OAAO,CACpB,MAAc,EACd,MAAc,EACd,OAAqB,EACrB,MAAqB,EACrB,IAAY;IAEZ,IAAI,aAAqB,CAAC;IAC1B,QAAQ,MAAM,EAAE;QACd,KAAK,KAAK;YACR,aAAa,GAAG,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YACzD,MAAM;QACR,qBAAqB;QACrB;YACE,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KACxC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CAAC,IAAI,CAAC,cAAwB,CAAA,CAAC,CAAC,MAAM,CAAC,cAAc,CAC3E,EACD,OAAO,CACR,CAAC;AACJ,CAAC,CACF;KACA,MAAM,CAAC,QAAQ,EAAE;IAChB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,8BAA8B;CAC5C,CAAC;KACD,MAAM,CAAC,QAAQ,EAAE;IAChB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,QAAQ;IACjB,WAAW,EAAE,gBAAgB;CAC9B,CAAC;KACD,MAAM,CAAC,aAAa,EAAE;IACrB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,cAAc;CAC5B,CAAC;KACD,MAAM,CAAC,gBAAgB,EAAE;IACxB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,iBAAiB;CAC/B,CAAC;KACD,MAAM,CAAC,YAAY,EAAE;IACpB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,aAAa;CAC3B,CAAC;KACD,MAAM,CAAC,SAAS,EAAE;IACjB,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,mBAAmB;CACjC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "https://github.com/ContinuousSecurityTooling/keycloak-reporter/blob/main/config/schema.json",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"title": "Keycloak Reporter Config",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"definitions": {},
|
|
7
|
+
"required": ["url", "clientId", "clientSecret"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"command": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"items": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"enum": ["listClients", "listUsers"]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"url": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Keycloak Server URL"
|
|
19
|
+
},
|
|
20
|
+
"clientId": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Keycloak Client used for reporting"
|
|
23
|
+
},
|
|
24
|
+
"clientSecret": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Keycloak Client Secret used for reporting"
|
|
27
|
+
},
|
|
28
|
+
"output": {
|
|
29
|
+
"type": "array",
|
|
30
|
+
"items": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"enum": ["webhook", "stdout"]
|
|
33
|
+
},
|
|
34
|
+
"description": "Output channel to use"
|
|
35
|
+
},
|
|
36
|
+
"format": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"items": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"enum": ["json", "csv"]
|
|
41
|
+
},
|
|
42
|
+
"description": "Report format"
|
|
43
|
+
},
|
|
44
|
+
"webhookType": {
|
|
45
|
+
"type": "array",
|
|
46
|
+
"items": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"enum": ["slack", "teams"]
|
|
49
|
+
},
|
|
50
|
+
"description": "Type of webhook"
|
|
51
|
+
},
|
|
52
|
+
"webhookMessage": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"description": "Message added to the webhook post"
|
|
55
|
+
},
|
|
56
|
+
"webhookUrl": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"description": "URL of the webhook"
|
|
59
|
+
},
|
|
60
|
+
"reports": {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"description": "Reports directory"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,83 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { listUsers, listClients } from './src/cli.js';
|
|
5
|
-
import { convertJSON2CSV } from './lib/convert.js';
|
|
6
|
-
import { post2Webhook } from './lib/output.js';
|
|
7
|
-
class WebhookConfig {
|
|
8
|
-
constructor(type, url, title) {
|
|
9
|
-
this.type = type;
|
|
10
|
-
this.url = url;
|
|
11
|
-
this.title = title;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
async function convert(format, output, config, json) {
|
|
15
|
-
let outputContent;
|
|
16
|
-
switch (format) {
|
|
17
|
-
case 'csv':
|
|
18
|
-
outputContent = (await convertJSON2CSV(json)).toString();
|
|
19
|
-
break;
|
|
20
|
-
// defaulting to JSON
|
|
21
|
-
default:
|
|
22
|
-
outputContent = JSON.stringify(json);
|
|
23
|
-
}
|
|
24
|
-
switch (output) {
|
|
25
|
-
case 'webhook':
|
|
26
|
-
try {
|
|
27
|
-
await post2Webhook(config.type, config.url, config.title, outputContent);
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
console.error('Error during sending webhook: ', e);
|
|
31
|
-
}
|
|
32
|
-
break;
|
|
33
|
-
// defaulting to standard out
|
|
34
|
-
default:
|
|
35
|
-
console.log(outputContent);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
yargs(hideBin(process.argv))
|
|
39
|
-
.command('listUsers [url] [clientId] [clientSecret]', 'fetches all users in the realms.',
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
41
|
-
() => { }, async (argv) => {
|
|
42
|
-
const users = await listUsers({
|
|
43
|
-
clientId: argv.clientId,
|
|
44
|
-
clientSecret: argv.clientSecret,
|
|
45
|
-
rootUrl: argv.url,
|
|
46
|
-
});
|
|
47
|
-
await convert(argv.format, argv.output, new WebhookConfig(argv.webhookType, argv.webhookUrl, 'User Listing'), users);
|
|
48
|
-
})
|
|
49
|
-
.command('listClients [url] [clientId] [clientSecret]', 'fetches all clients in the realms.',
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
51
|
-
() => { }, async (argv) => {
|
|
52
|
-
const clients = await listClients({
|
|
53
|
-
clientId: argv.clientId,
|
|
54
|
-
clientSecret: argv.clientSecret,
|
|
55
|
-
rootUrl: argv.url,
|
|
56
|
-
});
|
|
57
|
-
await convert(argv.format, argv.output, new WebhookConfig(argv.webhookType, argv.webhookUrl, 'Client Listing'), clients);
|
|
58
|
-
})
|
|
59
|
-
.option('format', {
|
|
60
|
-
alias: 'f',
|
|
61
|
-
type: 'string',
|
|
62
|
-
default: 'json',
|
|
63
|
-
description: 'output format, e.g. JSON|CSV',
|
|
64
|
-
})
|
|
65
|
-
.option('output', {
|
|
66
|
-
alias: 'o',
|
|
67
|
-
type: 'string',
|
|
68
|
-
default: 'stdout',
|
|
69
|
-
description: 'output channel',
|
|
70
|
-
})
|
|
71
|
-
.option('webhookType', {
|
|
72
|
-
alias: 'w',
|
|
73
|
-
type: 'string',
|
|
74
|
-
default: 'slack',
|
|
75
|
-
description: 'Webhook Type',
|
|
76
|
-
})
|
|
77
|
-
.option('webhookUrl', {
|
|
78
|
-
alias: 't',
|
|
79
|
-
type: 'string',
|
|
80
|
-
description: 'Webhook URL',
|
|
81
|
-
})
|
|
82
|
-
.parse();
|
|
1
|
+
export { listUsers, listClients } from './src/cli.js';
|
|
2
|
+
export { convertJSON2CSV } from './lib/convert.js';
|
|
3
|
+
export { post2Webhook } from './lib/output.js';
|
|
83
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/lib/client.js
CHANGED
|
@@ -16,7 +16,7 @@ export async function createClient(options) {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
catch (e) {
|
|
19
|
-
console.error('Check Client Config:', e.response.data.error_description);
|
|
19
|
+
console.error('Check Client Config:', e.response ? e.response.data.error_description : e);
|
|
20
20
|
return Promise.reject();
|
|
21
21
|
}
|
|
22
22
|
const keycloakIssuer = await Issuer.discover(`${options.rootUrl}/realms/master`);
|
package/dist/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAE5D,oCAAoC;AACpC,MAAM,aAAa,GAAG,EAAE,CAAC;AAQzB,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAgB;IACjD,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,SAAS,EAAE,QAAQ;KACpB,CAAC,CAAC;IAEH,IAAI;QACF,eAAe;QACf,MAAM,aAAa,CAAC,IAAI,CAAC;YACvB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,SAAS,EAAE,oBAAoB;SAChC,CAAC,CAAC;KACJ;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,aAAa,MAAM,iCAAiC,CAAC;AAE5D,oCAAoC;AACpC,MAAM,aAAa,GAAG,EAAE,CAAC;AAQzB,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAgB;IACjD,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,SAAS,EAAE,QAAQ;KACpB,CAAC,CAAC;IAEH,IAAI;QACF,eAAe;QACf,MAAM,aAAa,CAAC,IAAI,CAAC;YACvB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,SAAS,EAAE,oBAAoB;SAChC,CAAC,CAAC;KACJ;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CACX,sBAAsB,EACtB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CACnD,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;KACzB;IAED,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,QAAQ,CAC1C,GAAG,OAAO,CAAC,OAAO,gBAAgB,CACnC,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC;QACvC,SAAS,EAAE,OAAO,CAAC,QAAQ;QAC3B,0BAA0B,EAAE,MAAM,EAAE,uCAAuC;KAC5E,CAAC,CAAC;IAEH,gCAAgC;IAChC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;QAClC,SAAS,EAAE,OAAO,CAAC,QAAQ;QAC3B,aAAa,EAAE,OAAO,CAAC,YAAY;QACnC,UAAU,EAAE,oBAAoB;KACjC,CAAC,CAAC;IAEH;;;;;gCAK4B;IAE5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/lib/convert.js
CHANGED
|
File without changes
|
package/dist/lib/convert.js.map
CHANGED
|
File without changes
|
package/dist/lib/output.js
CHANGED
|
@@ -5,7 +5,7 @@ var WebhookType;
|
|
|
5
5
|
WebhookType["SLACK"] = "slack";
|
|
6
6
|
WebhookType["TEAMS"] = "teams";
|
|
7
7
|
})(WebhookType || (WebhookType = {}));
|
|
8
|
-
export async function post2Webhook(type, url, title, reportContent) {
|
|
8
|
+
export async function post2Webhook(type, url, title, reportContent, text) {
|
|
9
9
|
//const title= 'Keycloak Reporting';
|
|
10
10
|
const date = new Date();
|
|
11
11
|
switch (type) {
|
|
@@ -33,6 +33,11 @@ export async function post2Webhook(type, url, title, reportContent) {
|
|
|
33
33
|
},
|
|
34
34
|
],
|
|
35
35
|
},
|
|
36
|
+
{
|
|
37
|
+
type: 'TextBlock',
|
|
38
|
+
text: text != null ? text : '',
|
|
39
|
+
wrap: true,
|
|
40
|
+
},
|
|
36
41
|
],
|
|
37
42
|
actions: [
|
|
38
43
|
{
|
|
@@ -72,6 +77,13 @@ export async function post2Webhook(type, url, title, reportContent) {
|
|
|
72
77
|
{
|
|
73
78
|
type: 'divider',
|
|
74
79
|
},
|
|
80
|
+
{
|
|
81
|
+
type: 'context',
|
|
82
|
+
elements: [{ type: 'plain_text', text: text != null ? text : '' }],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: 'divider',
|
|
86
|
+
},
|
|
75
87
|
{
|
|
76
88
|
type: 'context',
|
|
77
89
|
elements: [
|