-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add core data collection for eks coverage #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,5 @@ dist/ | |
| .DS_Store | ||
| # TODO: Change this to match the specific plugin name | ||
| /plugin-* | ||
|
|
||
| .ai/ | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,101 @@ | ||
| # Compliance Framework Plugin Template | ||
| # AWS EKS CCF Plugin | ||
|
|
||
| This is a template for building a compliance framework plugin. | ||
| This plugin collects read-only Amazon EKS data, evaluates CCF Rego policy bundles, and emits evidence back through the CCF agent. | ||
|
|
||
| Inspect main.go for a detailed description of how to build the plugin. | ||
| ## Supported Resource Families | ||
|
|
||
| ## Prerequisites | ||
| The collector evaluates policies for: | ||
|
|
||
| * GoReleaser https://goreleaser.com/install/ | ||
| - EKS clusters | ||
| - EKS managed node groups | ||
| - EKS managed add-ons | ||
|
|
||
| ## Building | ||
| ## How It Fits In CCF | ||
|
|
||
| Once you are ready to serve the plugin, you need to build the binaries which can be used by the agent. | ||
| The CCF agent starts this binary through HashiCorp `go-plugin`, passes configuration and policy paths over gRPC, and receives generated evidence through the runner callback. This repository does not call the CCF API directly. | ||
|
|
||
| ```shell | ||
| goreleaser release --snapshot --clean | ||
| ``` | ||
| ## Default Policy Bundle Mapping | ||
|
|
||
| ## Usage | ||
| | Repository | Behavior | Primary input | | ||
| | --- | --- | --- | | ||
| | `plugin-aws-eks-policies` | `cluster` | `input.cluster` + `input.cluster_context` | | ||
| | `plugin-aws-eks-nodegroup-policies` | `nodegroup` | `input.nodegroup` + `input.nodegroup_context` | | ||
| | `plugin-aws-eks-addon-policies` | `addon` | `input.addon` + `input.addon_context` | | ||
|
|
||
| You can use this plugin by passing it to the compliance agent or by specifying it in the agent config | ||
| Each bundle evaluates one resource family at a time. Cluster context includes summarized related managed node groups and add-ons so cluster-level policies can check required add-ons without evaluating add-on policies against cluster input. | ||
|
|
||
| ```shell | ||
| agent --plugin=[PATH_TO_YOUR_BINARY] | ||
| ``` | ||
| ## Configuration | ||
|
|
||
| ```yaml | ||
| # AGENT CONFIG | ||
| The plugin expects: | ||
|
|
||
| - AWS credentials through the default AWS SDK credential chain | ||
| - target regions from `config.regions` or `config.region` | ||
| - `AWS_REGION` as a fallback when plugin config does not provide a region | ||
|
|
||
| verbosity: 2 | ||
| Any agent-supplied `policy_data` is passed through to Rego as `data.*`. | ||
|
|
||
| api: | ||
| url: http://localhost:8080 | ||
| Example agent plugin config: | ||
|
|
||
| ```yaml | ||
| plugins: | ||
| # Plugin execution identifier | ||
| myplugin: | ||
| # Config mapping passed through to Configure lifecycle event | ||
| config: | ||
| anykey: "anyval" | ||
| policy_labels: "{\"my_key\":\"my_value\"}" | ||
| # Compatible protocol version: Defaults to 1, can also be determined a plugin image manifest annotation of "org.ccf.plugin.protocol.version=2" | ||
| aws-eks: | ||
| protocol_version: 2 | ||
| # Source to plugin executable location. Can be an OCI image or local executable | ||
| source: /path/to/dist/plugin | ||
| # List to all policies to pass to plugin, all may be processed or filtered later via policy_behavior | ||
| config: | ||
| regions: "eu-west-2,us-east-1" | ||
| policies: | ||
| - /path/to/policy/bundle.tar.gz | ||
| # Policy behaviour can be defined to later filter policies to specific bundles per execution | ||
| # This is useful if your plugin proccesses more than 1 type of component | ||
| policy_behavior: | ||
| string-to-match-to-policy: | ||
| - "associated-behavior-1" | ||
| # Policy data is passed to the plugin for evaluation, can be used to customize evaluation parameters | ||
| policy_data: | ||
| policy_data_key: "policy_data_value" | ||
|
|
||
| - /path/to/plugin-aws-eks-policies/dist/bundle.tar.gz | ||
| - /path/to/plugin-aws-eks-nodegroup-policies/dist/bundle.tar.gz | ||
| - /path/to/plugin-aws-eks-addon-policies/dist/bundle.tar.gz | ||
| ``` | ||
|
|
||
| ## Data Collected | ||
|
|
||
| Depending on the selected policy bundles, the plugin collects and reuses: | ||
|
|
||
| - `ListClusters` and `DescribeCluster` | ||
| - `ListNodegroups` and `DescribeNodegroup` | ||
| - `ListAddons` and `DescribeAddon` | ||
|
|
||
| The plugin collects shared regional datasets once and reuses them across resource-family evaluation to reduce AWS API calls. | ||
|
|
||
| ## IAM Permissions | ||
|
|
||
| The AWS principal used by the plugin needs read-only EKS permissions for the configured regions: | ||
|
|
||
| ```json | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": [ | ||
| "eks:ListClusters", | ||
| "eks:DescribeCluster", | ||
| "eks:ListNodegroups", | ||
| "eks:DescribeNodegroup", | ||
| "eks:ListAddons", | ||
| "eks:DescribeAddon" | ||
| ], | ||
| "Resource": "*" | ||
| } | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| Run the local test suite with: | ||
|
|
||
| ```shell | ||
| go test ./... | ||
| ``` | ||
|
|
||
| You can also use `make run` to build this plugin and execute against the agent, if the agent is located in the parent directory. See Makefile:run | ||
| Or use the Makefile wrapper: | ||
|
|
||
| ```shell | ||
| make test | ||
| ``` | ||
|
|
||
| Build the plugin binary with: | ||
|
|
||
| ```shell | ||
| make build | ||
| ``` | ||
|
|
||
| This writes the compiled plugin to `dist/plugin`. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/service/eks/types" | ||
| "github.com/compliance-framework/agent/runner/proto" | ||
| ) | ||
|
|
||
| func EvaluateAddonPolicies(deps EvaluationDependencies, policyPaths []string, addons []types.Addon, region string, datasets RegionDatasets) ResourceEvaluationErrors { | ||
| return EvaluateResources( | ||
| deps, | ||
| policyPaths, | ||
| addons, | ||
| func(addon types.Addon) ResourceEvidenceContext { | ||
| return BuildAddonEvidenceContext(addon, region) | ||
| }, | ||
| func(addon types.Addon) (interface{}, error) { | ||
| return BuildAddonPolicyInput(addon, region, datasets) | ||
| }, | ||
| func(addon types.Addon, err error) { | ||
| deps.Logger.Error("unable to build EKS add-on policy input", "cluster_name", aws.ToString(addon.ClusterName), "addon_name", aws.ToString(addon.AddonName), "region", region, "error", err) | ||
| }, | ||
| func(evidences []*proto.Evidence, addon types.Addon) { | ||
| PrefixEvidenceTitles(evidences, AddonDisplayName(addon)) | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| func BuildAddonPolicyInput(addon types.Addon, region string, datasets RegionDatasets) (map[string]interface{}, error) { | ||
| addonValue, err := ToInterfaceMap(addon) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| contextValue, err := ToInterfaceMap(buildAddonSupplementaryContext(addon, region, datasets)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return map[string]interface{}{ | ||
| "addon": addonValue, | ||
| "addon_context": contextValue, | ||
| }, nil | ||
| } | ||
|
|
||
| func buildAddonSupplementaryContext(addon types.Addon, region string, datasets RegionDatasets) map[string]interface{} { | ||
| clusterName := aws.ToString(addon.ClusterName) | ||
|
|
||
| return map[string]interface{}{ | ||
| "current": map[string]interface{}{ | ||
| "cluster_name": clusterName, | ||
| "addon_name": aws.ToString(addon.AddonName), | ||
| "addon_arn": aws.ToString(addon.AddonArn), | ||
| "region": region, | ||
| "status": string(addon.Status), | ||
| "addon_version": aws.ToString(addon.AddonVersion), | ||
| "health_issue_count": addonHealthIssueCount(addon), | ||
| "owner": aws.ToString(addon.Owner), | ||
| "publisher": aws.ToString(addon.Publisher), | ||
| "tags_present": len(addon.Tags) > 0, | ||
| "has_service_account_role": aws.ToString(addon.ServiceAccountRoleArn) != "", | ||
| }, | ||
| "cluster": findClusterByName(datasets.Clusters, clusterName), | ||
| } | ||
| } | ||
|
|
||
| func AddonDisplayName(addon types.Addon) string { | ||
| return aws.ToString(addon.AddonName) | ||
| } | ||
|
|
||
| func addonHealthIssueCount(addon types.Addon) int { | ||
| if addon.Health == nil { | ||
| return 0 | ||
| } | ||
| return len(addon.Health.Issues) | ||
| } | ||
|
|
||
| func filterAddonsByCluster(addons []types.Addon, clusterName string) []types.Addon { | ||
| filtered := make([]types.Addon, 0) | ||
| for _, addon := range addons { | ||
| if aws.ToString(addon.ClusterName) == clusterName { | ||
| filtered = append(filtered, addon) | ||
| } | ||
| } | ||
| return filtered | ||
| } | ||
|
|
||
| func addonNames(addons []types.Addon) []string { | ||
| names := make([]string, 0, len(addons)) | ||
| for _, addon := range addons { | ||
| if name := aws.ToString(addon.AddonName); name != "" { | ||
| names = append(names, name) | ||
| } | ||
| } | ||
| return names | ||
| } | ||
|
|
||
| func activeAddonNames(addons []types.Addon) []string { | ||
| names := make([]string, 0, len(addons)) | ||
| for _, addon := range addons { | ||
| if addon.Status == types.AddonStatusActive { | ||
| if name := aws.ToString(addon.AddonName); name != "" { | ||
| names = append(names, name) | ||
| } | ||
| } | ||
| } | ||
| return names | ||
| } | ||
|
|
||
| func findClusterByName(clusters []types.Cluster, clusterName string) *types.Cluster { | ||
| for _, cluster := range clusters { | ||
| if aws.ToString(cluster.Name) == clusterName { | ||
| clusterCopy := cluster | ||
| return &clusterCopy | ||
| } | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Go 1.26.1 has known security advisories.
OSV Scanner reports 18 LOW severity vulnerabilities in Go 1.26.1 stdlib (e.g., GO-2026-4864 through GO-2026-5039), including issues in
crypto/x509,html/template,net/http, and other stdlib packages. Consider upgrading to a patched Go version when available.🤖 Prompt for AI Agents
Source: Linters/SAST tools