Skip to content

Commit 9425b54

Browse files
author
Jeff McCormick
committed
add basic auditing capability
1 parent 0dc397d commit 9425b54

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

apiserver/root.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ var RESTClient *rest.RESTClient
4141
// Clientset ...
4242
var Clientset *kubernetes.Clientset
4343

44+
// AuditFlag if set to true will cause auditing to occur in the logs
45+
var AuditFlag bool
46+
4447
// DebugFlag is the debug flag value
4548
var DebugFlag bool
4649

@@ -62,6 +65,8 @@ var Credentials map[string]string
6265
func init() {
6366
BasicAuth = true
6467

68+
AuditFlag = false
69+
6570
log.Infoln("apiserver starts")
6671

6772
getCredentials()
@@ -126,6 +131,11 @@ func initConfig() {
126131
log.Debug("config file not found")
127132
}
128133

134+
AuditFlag = viper.GetBool("Pgo.Audit")
135+
if AuditFlag {
136+
log.Info("audit flag is set to true")
137+
}
138+
129139
if DebugFlag || viper.GetBool("Pgo.Debug") {
130140
log.Debug("debug flag is set to true")
131141
log.SetLevel(log.DebugLevel)
@@ -231,6 +241,10 @@ func Authn(where string, w http.ResponseWriter, r *http.Request) error {
231241
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
232242

233243
username, password, authOK := r.BasicAuth()
244+
if AuditFlag {
245+
log.Infof("[audit] %s username=[%s] method=[%s]\n", where, username, r.Method)
246+
}
247+
234248
log.Debugf("Authn Attempt %s username=[%s] password=[%s]\n", where, username, password)
235249
if authOK == false {
236250
http.Error(w, "Not authorized", 401)

conf/apiserver/pgo.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Namespace: demo
22
Cluster:
33
CCPImagePrefix: crunchydata
4-
CCPImageTag: centos7-10.1-1.7.0
4+
CCPImageTag: centos7-10.1-1.7.1
55
Port: 5432
66
User: testuser
77
Database: userdb
@@ -22,6 +22,7 @@ ReplicaStorage:
2222
Size: 200M
2323
StorageType: create
2424
Pgo:
25+
Audit: false
2526
LSPVCTemplate: /config/pgo.lspvc-template.json
2627
LoadTemplate: /config/pgo.load-template.json
2728
COImagePrefix: crunchydata

docs/operator-docs.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ ReplicaStorage:
546546
Size: 200M
547547
StorageType: create
548548
Pgo:
549+
Audit: true
549550
APIServerUrl: http://localhost:8080
550551
LSPVCTemplate: /config/pgo.lspvc-template.json
551552
CSVLoadTemplate: /config/pgo.load-template.json
@@ -594,6 +595,7 @@ Values in the pgo configuration file have the following meaning:
594595
|Pgo.LoadTemplate | the load template file used for load jobs
595596
|Pgo.COImagePrefix | image tag prefix to use for the Operator containers
596597
|Pgo.COImageTag | image tag to use for the Operator containers
598+
|Pgo.Audit | boolean, if set to true will cause each apiserver call to be logged with an *audit* marking
597599
|======================
598600

599601
*NOTE*: Regarding the PVC access mode variable; this is automatically set to ReadWriteMany but

0 commit comments

Comments
 (0)