Skip to content
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

fix: Fix aws-node service account irsa bug #31

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## Unreleased
## v0.9.3 (2023-05-15)

### Fix

- Fix aws-node service account irsa bug

## v0.9.2 (2023-05-03)

### Fix

Expand Down
10 changes: 9 additions & 1 deletion hardeneks/cluster_wide/security/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ def check(self, resources: Resources):
name="aws-node", namespace="kube-system"
)
self.result = Result(status=True, resource_type="Daemonset")
if daemonset.spec.template.spec.service_account_name == "aws-node":
v1 = client.CoreV1Api()
service_account = v1.read_namespaced_service_account(
name=daemonset.spec.template.spec.service_account_name,
namespace="kube-system",
)
if (
"eks.amazonaws.com/role-arn"
not in service_account.metadata.annotations
):
self.result = Result(
status=False, resources=["aws-node"], resource_type="Daemonset"
)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hardeneks"
version = "0.9.2"
version = "0.9.3"
description = ""
authors = ["Doruk Ozturk <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -41,7 +41,7 @@ exclude = '''

[tool.commitizen]
name = "cz_conventional_commits"
version = "0.9.2"
version = "0.9.3"
version_files = [
"pyproject.toml:[tool.commitizen]\nversion",
"pyproject.toml:[tool.poetry]\nname = \"commitizen\"\nversion",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"apiVersion": "v1",
"kind": "ServiceAccount",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"ServiceAccount\",\"metadata\":{\"annotations\":{},\"labels\":{\"app.kubernetes.io/instance\":\"aws-vpc-cni\",\"app.kubernetes.io/name\":\"aws-node\",\"app.kubernetes.io/version\":\"v1.11.4\",\"k8s-app\":\"aws-node\"},\"name\":\"aws-node\",\"namespace\":\"kube-system\"}}\n"
},
"creationTimestamp": "2023-04-14T12:17:01Z",
"labels": {
"app.kubernetes.io/instance": "aws-vpc-cni",
"app.kubernetes.io/name": "aws-node",
"app.kubernetes.io/version": "v1.11.4",
"k8s-app": "aws-node"
},
"name": "aws-node",
"namespace": "kube-system",
"resourceVersion": "3691",
"uid": "122cc1c7-ba3b-4133-9b7a-b847398cf11b"
}
}
22 changes: 17 additions & 5 deletions tests/test_security_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,32 @@ def test_check_access_to_instance_profile(mocked_client):


@patch("kubernetes.client.AppsV1Api.read_namespaced_daemon_set")
def test_check_aws_node_daemonset_service_account(mocked_client):
test_data = (
@patch("kubernetes.client.CoreV1Api.read_namespaced_service_account")
def test_check_aws_node_daemonset_service_account(
mocked_core_api, mocked_apps_api
):
daemon_set_data = (
Path.cwd()
/ "tests"
/ "data"
/ "check_aws_node_daemonset_service_account"
/ "daemon_sets_api_response.json"
)
mocked_client.return_value = get_response(
service_account_data = (
Path.cwd()
/ "tests"
/ "data"
/ "check_aws_node_daemonset_service_account"
/ "service_accounts_api_response.json"
)
mocked_apps_api.return_value = get_response(
kubernetes.client.AppsV1Api,
test_data,
daemon_set_data,
"V1DaemonSet",
)

mocked_core_api.return_value = get_response(
kubernetes.client.CoreV1Api, service_account_data, "V1ServiceAccount"
)
namespaced_resources = NamespacedResources(
"some_region", "some_context", "some_cluster", "some_ns"
)
Expand Down