Skip to content

Commit ed857a7

Browse files
committed
Update README with demo log
1 parent 501d132 commit ed857a7

File tree

1 file changed

+65
-23
lines changed

1 file changed

+65
-23
lines changed

README.md

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,87 @@ audit2rbac is in the nascent stages of development, and will change internal and
1111

1212
## User Instructions
1313

14-
1. Obtain a Kubernetes audit log containing all the API requests you expect your user to perform
15-
* The log must be in JSON format (requires running an API server with `--feature-gates=AdvancedAudit=true` and a `--audit-policy-file` defined... see [documentation](https://kubernetes.io/docs/tasks/debug-application-cluster/audit/#advanced-audit) for more details)
16-
* `v1alpha1` or `v1beta1` audit events are supported
17-
* The `Metadata` log level works best to minimize log size
14+
1. Obtain a Kubernetes audit log containing all the API requests you expect your user to perform:
15+
* The log must be in JSON format. This requires running an API server with `--feature-gates=AdvancedAudit=true` and an `--audit-policy-file` defined. See [documentation](https://kubernetes.io/docs/tasks/debug-application-cluster/audit/#advanced-audit) for more details.
16+
* `v1alpha1` or `v1beta1` audit events are supported.
17+
* The `Metadata` log level works best to minimize log size.
1818
* To exercise all API calls, it is sometimes necessary to grant broad access to a user or application to avoid short-circuiting code paths on failed API requests. This should be done cautiously, ideally in a development environment.
19-
2. Identify a specific user you want to generate roles for. This can be a normal user with a username like `bob` or a service account with a username like `system:serviceaccount:my-namespace:my-service-account`.
20-
3. Run `audit2rbac`, capturing the output
19+
* A ([sample log](testdata/demo.log)) containing requests from `alice`, `bob`, and the service account `ns1:sa1` is available.
20+
2. Identify a specific user you want to scan for audit events for and generate roles and role bindings for:
21+
* Specify a normal user with `--user <username>`
22+
* Specify a service account with `--serviceaccount <namespace>:<name>`
23+
3. Run `audit2rbac`, capturing the output:
2124
```sh
22-
audit2rbac --filename audit.log --user system:serviceaccount:my-namespace:my-user > roles.yaml
23-
24-
Loading events...............................................
25-
Evaluating API calls...
26-
Generating roles...
27-
Complete!
25+
curl -s -O -L https://github.com/liggitt/audit2rbac/raw/master/testdata/demo.log
26+
audit2rbac --filename demo.log --user alice > alice-roles.yaml
27+
audit2rbac --filename demo.log --user bob > bob-roles.yaml
28+
audit2rbac --filename demo.log --serviceaccount ns1:sa1 > sa1-roles.yaml
2829
```
2930
4. Inspect the output to verify the generated roles/bindings:
3031
```sh
31-
more roles.yaml
32+
more alice-roles.yaml
33+
```
3234

35+
```yaml
3336
apiVersion: rbac.authorization.k8s.io/v1
34-
kind: ClusterRole
37+
kind: Role
3538
metadata:
3639
creationTimestamp: null
3740
labels:
3841
audit2rbac.liggitt.net/generated: "true"
39-
audit2rbac.liggitt.net/user: my-user
40-
name: audit2rbac:my-user
42+
audit2rbac.liggitt.net/user: alice
43+
name: audit2rbac:alice
44+
namespace: ns1
4145
rules:
4246
- apiGroups:
43-
...
47+
- ""
48+
resources:
49+
- configmaps
50+
verbs:
51+
- get
52+
- list
53+
- watch
54+
- apiGroups:
55+
- ""
56+
resources:
57+
- pods
58+
verbs:
59+
- get
60+
- list
61+
- watch
62+
- apiGroups:
63+
- ""
64+
resources:
65+
- secrets
66+
verbs:
67+
- get
68+
- list
69+
- watch
70+
---
71+
apiVersion: rbac.authorization.k8s.io/v1
72+
kind: RoleBinding
73+
metadata:
74+
creationTimestamp: null
75+
labels:
76+
audit2rbac.liggitt.net/generated: "true"
77+
audit2rbac.liggitt.net/user: alice
78+
name: audit2rbac:alice
79+
namespace: ns1
80+
roleRef:
81+
apiGroup: rbac.authorization.k8s.io
82+
kind: Role
83+
name: audit2rbac:alice
84+
subjects:
85+
- apiGroup: rbac.authorization.k8s.io
86+
kind: User
87+
name: alice
4488
```
4589
5. Load the generated roles/bindings:
4690
```sh
4791
kubectl create -f roles.yaml
4892
49-
clusterrole "audit2rbac:my-user" created
50-
clusterrolebinding "audit2rbac:my-user" created
51-
role "audit2rbac:my-user" created
52-
rolebinding "audit2rbac:my-user" created
93+
role "audit2rbac:alice" created
94+
rolebinding "audit2rbac:alice" created
5395
```
5496

5597
## Developer Instructions
@@ -58,11 +100,11 @@ Requirements:
58100
* Go 1.8+
59101
* Glide 0.12.3+
60102

61-
To download, install dependencies, and build:
103+
To build and install from source:
62104
```sh
63105
go get -d github.com/liggitt/audit2rbac
64106
cd $GOPATH/src/github.com/liggitt/audit2rbac
65107
git fetch --tags
66108
make install-deps
67-
make
109+
make install
68110
```

0 commit comments

Comments
 (0)