-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
#936 adding support for AuditLogConfigs in IAM Policies #1531
Closed
adamenger
wants to merge
5
commits into
hashicorp:2.0.0
from
adamenger:atom/adding-auditlogconfig-support
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6b9b7ab
#936 adding support for AuditLogConfigs in IAM Policies
68f9a4f
#936 adding support for AuditLogConfigs in IAM Policies
380fb21
#936. updateMasks were the missing key
d049715
#936 adding documentation for using audit_config
5a63a1b
an extra *
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,3 +154,67 @@ func rolesToMembersMap(bindings []*cloudresourcemanager.Binding) map[string]map[ | |
} | ||
return bm | ||
} | ||
|
||
// Merge multiple Audit Configs such that configs with the same service result in | ||
// a single exemption list with combined members | ||
func mergeAuditConfigs(audit_configs []*cloudresourcemanager.AuditConfig) []*cloudresourcemanager.AuditConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a general rule of thumb, camelCase, not snake_case, is preferred. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I'll get this fixed up. |
||
am := auditConfigToServiceMap(audit_configs) | ||
ac := make([]*cloudresourcemanager.AuditConfig, 0) | ||
|
||
for service, audit_log_configs := range am { | ||
var a cloudresourcemanager.AuditConfig | ||
a.Service = service | ||
a.AuditLogConfigs = make([]*cloudresourcemanager.AuditLogConfig, 0) | ||
|
||
for k, v := range audit_log_configs { | ||
|
||
var alc cloudresourcemanager.AuditLogConfig | ||
alc.LogType = k | ||
for member, _ := range v { | ||
alc.ExemptedMembers = append(alc.ExemptedMembers, member) | ||
} | ||
|
||
a.AuditLogConfigs = append(a.AuditLogConfigs, &alc) | ||
} | ||
|
||
if len(a.AuditLogConfigs) > 0 { | ||
ac = append(ac, &a) | ||
} | ||
} | ||
|
||
return ac | ||
} | ||
|
||
// Build a service map with the log_type and bindings below it | ||
func auditConfigToServiceMap(audit_config []*cloudresourcemanager.AuditConfig) map[string]map[string]map[string]bool { | ||
ac := make(map[string]map[string]map[string]bool) | ||
|
||
// Get each config | ||
for _, c := range audit_config { | ||
|
||
// Initialize service map | ||
if _, ok := ac[c.Service]; !ok { | ||
ac[c.Service] = make(map[string]map[string]bool) | ||
} | ||
|
||
// loop through audit log configs | ||
for _, lc := range c.AuditLogConfigs { | ||
|
||
// Initialize service map | ||
if _, ok := ac[c.Service][lc.LogType]; !ok { | ||
ac[c.Service][lc.LogType] = make(map[string]bool) | ||
} | ||
|
||
// Get each member (user/principal) for the binding | ||
for _, m := range lc.ExemptedMembers { | ||
// Add the member | ||
if _, ok := ac[c.Service][lc.LogType][m]; !ok { | ||
ac[c.Service][lc.LogType][m] = true | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
return ac | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,25 @@ data "google_iam_policy" "admin" { | |
"user:[email protected]", | ||
] | ||
} | ||
|
||
audit_config { | ||
service = "cloudkms.googleapis.com" | ||
audit_log_configs = [ | ||
{ | ||
log_type = "DATA_READ", | ||
exempted_members = [ | ||
"user:[email protected]", | ||
] | ||
}, | ||
{ | ||
"logType": "DATA_WRITE", | ||
}, | ||
{ | ||
"logType": "ADMIN_READ", | ||
} | ||
] | ||
} | ||
|
||
} | ||
``` | ||
|
||
|
@@ -64,6 +83,12 @@ each accept the following arguments: | |
* **group:{emailid}**: An email address that represents a Google group. For example, [email protected]. | ||
* **domain:{domain}**: A Google Apps domain name that represents all the users of that domain. For example, google.com or example.com. | ||
|
||
* `audit_config` (Optional) - A nested configuration block that defines logging additional configuration for your project. | ||
* `service` (Required) Defines a service that will be enabled for audit logging. For example, `storage.googleapis.com`, `cloudsql.googleapis.com`. `allServices` is a special value that covers all services. | ||
* `audit_log_configs` (Required) A nested block that defines the operations you'd like to log. | ||
* `log_type` (Required) Defines the logging level. `DATA_READ`, `DATA_WRITE` and `ADMIN_READ` capture different types of events. See [the audit configuration documentation](https://cloud.google.com/resource-manager/reference/rest/Shared.Types/AuditConfig) for more details. | ||
* `exempted_members` (Optional) Specifies the identities that are exempt from these types of logging operations. Follows the same format of the `members` array for `binding`. | ||
|
||
## Attributes Reference | ||
|
||
The following attribute is exported: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the order of the exempted members matter? Would you ever want to reference them using interpolation? If the answer to both is "no", this would probably be better off as a Set.