-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathpki_audit_visibility.go
216 lines (185 loc) · 4.91 KB
/
pki_audit_visibility.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package healthcheck
import (
"fmt"
"github.com/hashicorp/go-secure-stdlib/parseutil"
)
var VisibleReqParams = []string{
"csr",
"certificate",
"issuer_ref",
"common_name",
"alt_names",
"other_sans",
"ip_sans",
"uri_sans",
"ttl",
"not_after",
"serial_number",
"key_type",
"private_key_format",
"managed_key_name",
"managed_key_id",
"ou",
"organization",
"country",
"locality",
"province",
"street_address",
"postal_code",
"permitted_dns_domains",
"policy_identifiers",
"ext_key_usage_oids",
}
var VisibleRespParams = []string{
"certificate",
"issuing_ca",
"serial_number",
"error",
"ca_chain",
}
var HiddenReqParams = []string{
"private_key",
"pem_bundle",
}
var HiddenRespParams = []string{
"private_key",
"pem_bundle",
}
type AuditVisibility struct {
Enabled bool
UnsupportedVersion bool
IgnoredParameters map[string]bool
TuneData map[string]interface{}
Fetcher *PathFetch
}
func NewAuditVisibilityCheck() Check {
return &AuditVisibility{
IgnoredParameters: make(map[string]bool),
}
}
func (h *AuditVisibility) Name() string {
return "audit_visibility"
}
func (h *AuditVisibility) IsEnabled() bool {
return h.Enabled
}
func (h *AuditVisibility) DefaultConfig() map[string]interface{} {
return map[string]interface{}{
"ignored_parameters": []string{},
}
}
func (h *AuditVisibility) LoadConfig(config map[string]interface{}) error {
var err error
coerced, err := StringList(config["ignored_parameters"])
if err != nil {
return fmt.Errorf("error parsing %v.ignored_parameters: %v", h.Name(), err)
}
for _, ignored := range coerced {
h.IgnoredParameters[ignored] = true
}
h.Enabled, err = parseutil.ParseBool(config["enabled"])
if err != nil {
return fmt.Errorf("error parsing %v.enabled: %w", h.Name(), err)
}
return nil
}
func (h *AuditVisibility) FetchResources(e *Executor) error {
var exit bool
var err error
exit, h.Fetcher, h.TuneData, err = fetchMountTune(e, func() {
h.UnsupportedVersion = true
})
if exit || err != nil {
return err
}
return nil
}
func (h *AuditVisibility) Evaluate(e *Executor) (results []*Result, err error) {
if h.UnsupportedVersion {
ret := Result{
Status: ResultInvalidVersion,
Endpoint: "/sys/mounts/{{mount}}/tune",
Message: "This health check requires Vault 1.9+ but an earlier version of Vault Server was contacted, preventing this health check from running.",
}
return []*Result{&ret}, nil
}
if h.Fetcher.IsSecretPermissionsError() {
ret := Result{
Status: ResultInsufficientPermissions,
Endpoint: "/sys/mounts/{{mount}}/tune",
Message: "Without this information, this health check is unable to function.",
}
if e.Client.Token() == "" {
ret.Message = "No token available so unable read the tune endpoint for this mount. " + ret.Message
} else {
ret.Message = "This token lacks permission to read the tune endpoint for this mount. " + ret.Message
}
results = append(results, &ret)
return
}
sourceMap := map[string][]string{
"audit_non_hmac_request_keys": VisibleReqParams,
"audit_non_hmac_response_keys": VisibleRespParams,
}
for source, visibleList := range sourceMap {
actual, err := StringList(h.TuneData[source])
if err != nil {
return nil, fmt.Errorf("error parsing %v from server: %v", source, err)
}
for _, param := range visibleList {
found := false
for _, tuned := range actual {
if param == tuned {
found = true
break
}
}
if !found {
ret := Result{
Status: ResultInformational,
Endpoint: "/sys/mounts/{{mount}}/tune",
Message: fmt.Sprintf("Mount currently HMACs %v because it is not in %v; as this is not a sensitive security parameter, it is encouraged to disable HMACing to allow better auditing of the PKI engine.", param, source),
}
results = append(results, &ret)
}
}
}
sourceMap = map[string][]string{
"audit_non_hmac_request_keys": HiddenReqParams,
"audit_non_hmac_response_keys": HiddenRespParams,
}
for source, hiddenList := range sourceMap {
actual, err := StringList(h.TuneData[source])
if err != nil {
return nil, fmt.Errorf("error parsing %v from server: %v", source, err)
}
for _, param := range hiddenList {
found := false
for _, tuned := range actual {
if param == tuned {
found = true
break
}
}
if found {
ret := Result{
Status: ResultWarning,
Endpoint: "/sys/mounts/{{mount}}/tune",
Message: fmt.Sprintf("Mount currently doesn't HMAC %v because it is in %v; as this is a sensitive security parameter it is encouraged to HMAC it in the Audit logs.", param, source),
}
results = append(results, &ret)
}
}
}
if len(results) == 0 {
ret := Result{
Status: ResultOK,
Endpoint: "/sys/mounts/{{mount}}/tune",
Message: "Mount audit information is configured appropriately.",
}
results = append(results, &ret)
}
return
}