Created
March 30, 2023 04:18
-
-
Save bb01100100/18f563f858ce9f91a76f4df3895f7c36 to your computer and use it in GitHub Desktop.
jq - summarise Confluent Cloud service account topic access
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
(INDEX($sa[] ; .id) | map_values(.name)) as $dict | |
| [(.[] | select(.principal[:7] == "User:sa"))] | |
| group_by(.principal) | |
| map( | |
{ | |
(first.principal[5:] as $p | |
| ($dict[$p] // ("ACL-for-non-existant-service-account: " + $p)) | |
): map( | |
((.resource_type | ascii_downcase) + "/"+ .resource_name) | |
) | |
} | |
) | |
|add |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can use
jq
to quickly summarise Confluent Cloud service account information, grouping by service account id and using some simple service-account reference data to obtain the name of the account.First thing is to obtain the list of ACLs for a given Confluent Cloud cluster, which we do via the
confluent
cli:% confluent kafka acl list -o json > cluster-acls.json
The output looks like the following:
Then we complement this with service account information, which includes the name of the account:
% confluent iam service-account list -o json > service-accounts.json
This looks like the following:
Line by line the attached script does the following:
service-accounts.json
file, relating the service account ID to its nameUser:<sa|u>-...
whereu
refers to a user (human) account andsa
refers to an application.group
the array of ACLs by principal name, creating individual arrays of ACLs for each principal. The output looks like{
principal
field from the first item in the group... Given all members will have the same principal, this is safe. We store the principal name in variable $p for use later.$p
) in our index, and if not found//
we set a default valueTOPIC
, which we downcase and suffix+ "/" +
with the actual name of the resourceadd
function to the array.Our final output looks like the following:
To run this we need to configure inputs correctly:
jq --argfile sa service-accounts.json -f summarise-acls.jq cluster-acls.json
Firstly we will
jq
that the variablesa
relates to theservice-accounts.json
file (our reference file). In the script on line 1 we refer to $sa.We then pass in the
jq
filter script above and finally the ACL json file.