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 hidden or 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can use
jqto 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
confluentcli:% confluent kafka acl list -o json > cluster-acls.jsonThe 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.jsonThis looks like the following:
Line by line the attached script does the following:
service-accounts.jsonfile, relating the service account ID to its nameUser:<sa|u>-...whereurefers to a user (human) account andsarefers to an application.groupthe array of ACLs by principal name, creating individual arrays of ACLs for each principal. The output looks like{principalfield 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 resourceaddfunction 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.jsonFirstly we will
jqthat the variablesarelates to theservice-accounts.jsonfile (our reference file). In the script on line 1 we refer to $sa.We then pass in the
jqfilter script above and finally the ACL json file.