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: add a few more permissions to reflect the current script requirements #1255

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

monteiro-renato
Copy link
Contributor

@monteiro-renato monteiro-renato commented Jan 22, 2025

To fit the current script's needs.

I'm working on a Github Action that can be re-used by multiple teams.

Summary by CodeRabbit

  • Permissions Update
    • Enhanced Kubernetes role permissions for service principal access
    • Added ability to delete configmaps
    • Expanded access to test runs with additional operations
    • Introduced new permissions for viewing pods and pod logs

@monteiro-renato monteiro-renato requested a review from a team as a code owner January 22, 2025 10:38
Copy link

coderabbitai bot commented Jan 22, 2025

📝 Walkthrough

Walkthrough

The pull request modifies the Kubernetes cluster role sp_access in the k6_tests_rg_rbac.tf file. The changes expand the permissions for the role by updating the verbs for existing resources like configmaps and testruns, and introducing new rules for pods and pods/log resources. These modifications increase the access level and operational capabilities of the sp_access role within the Kubernetes cluster.

Changes

File Change Summary
infrastructure/adminservices-test/altinn-monitor-test-rg/k6_tests_rg_rbac.tf - Updated configmaps verbs to include delete
- Expanded testruns verbs to include get, watch, and delete
- Added new rules for pods with get and list operations
- Added new rule for pods/log with get and list operations

Possibly related PRs

Suggested reviewers

  • tjololo

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
infrastructure/adminservices-test/altinn-monitor-test-rg/k6_tests_rg_rbac.tf (1)

53-61: LGTM: Pod read access is appropriately restricted.

The new rules for pods and pod logs are:

  • Limited to read-only operations (get, list)
  • More restrictive than the dev_access role
  • Necessary for monitoring test execution

These permissions follow the principle of least privilege while providing the required functionality for test monitoring.

Consider documenting these permission requirements in the repository's documentation to help other teams understand the security implications and requirements when reusing this GitHub Action.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebbe408 and 04ddf40.

📒 Files selected for processing (1)
  • infrastructure/adminservices-test/altinn-monitor-test-rg/k6_tests_rg_rbac.tf (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
infrastructure/adminservices-test/altinn-monitor-test-rg/k6_tests_rg_rbac.tf (2)

51-51: LGTM: TestRun monitoring permissions are appropriate.

The addition of get, watch, and delete permissions for TestRuns is necessary for monitoring test execution and cleanup. These permissions match the dev_access role and are properly scoped to the k6.io API group.


41-41: LGTM: ConfigMap delete permission aligns with cleanup requirements.

The addition of the "delete" permission for ConfigMaps is appropriate for test cleanup operations and matches the permissions in the dev_access role.

Let's verify the script's ConfigMap cleanup requirements:

✅ Verification successful

✓ Verified: ConfigMap permissions match script requirements

The RBAC permissions ["create", "update", "delete"] align perfectly with the script's operations:

  • Creates ConfigMaps for test archives
  • Deletes ConfigMaps during cleanup
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ConfigMap cleanup operations in the referenced script
curl -s https://raw.githubusercontent.com/Altinn/dialogporten/8f5ce91209f5417eba04e60d8ce6c170f9969a16/tests/k6/tests/scripts/run-test-in-k8s.sh | grep -A 5 "configmap"

Length of output: 1644

Copy link
Member

@bengtfredh bengtfredh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

github-actions bot commented Jan 22, 2025

Terraform environment test

Format and Style 🖌success

Initialization ⚙️success

Validation 🤖success

Validation Output

Success! The configuration is valid.


Plan 📖success

Show Plan

[Lines containing Refreshing state removed]
[Truncated to 120000 bytes! See logoutput for complete plan]
Acquiring state lock. This may take a few moments...
data.azurerm_resource_group.rg_dp_prod: Reading...
data.azurerm_resource_group.rd_dp_test["dp-be-test-rg"]: Reading...
data.azurerm_log_analytics_workspace.dp_law_test["dp-be-test-insightsWorkspace"]: Reading...
data.azurerm_log_analytics_workspace.dp_law_test["dp-be-yt01-insightsWorkspace"]: Reading...
data.azurerm_resource_group.rd_dp_test["dp-be-yt01-rg"]: Reading...
data.azurerm_resource_group.rd_dp_test["dp-be-test-rg"]: Read complete after 1s [id=/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-test-rg]
data.azurerm_resource_group.rd_dp_test["dp-be-yt01-rg"]: Read complete after 1s [id=/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-yt01-rg]
data.azurerm_client_config.current: Reading...
data.azurerm_monitor_data_collection_rule.prometheus: Reading...
data.azurerm_client_config.current: Read complete after 0s [id=Y2xpZW50Q29uZmlncy9jbGllbnRJZD1mMDNmNzU3OS01ZjM5LTRkN2YtYmNlYS04ZTVjYjZkN2FjYTQ7b2JqZWN0SWQ9MDJiMTdkMjgtN2VjOC00MDg0LTkyY2UtZDI2MDUxZmE0OTk4O3N1YnNjcmlwdGlvbklkPTFjZThlOWFmLWMyZDYtNDRlNy05YzVlLTA5OWEzMDgwNTZmZTt0ZW5hbnRJZD1jZDAwMjZkOC0yODNiLTRhNTUtOWJmYS1kMGVmNGE4YmEyMWM=]
data.azurerm_resource_group.rg_dp_prod: Read complete after 1s [id=/subscriptions/c595f787-450d-4c57-84fa-abc5f95d5459/resourceGroups/dp-be-prod-rg]
data.azurerm_log_analytics_workspace.dp_law_prod: Reading...
data.azurerm_resource_group.rg_dp_stag: Reading...
data.azurerm_log_analytics_workspace.dp_law_test["dp-be-test-insightsWorkspace"]: Read complete after 1s [id=/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-test-rg/providers/Microsoft.OperationalInsights/workspaces/dp-be-test-insightsWorkspace]
data.azurerm_log_analytics_workspace.dp_law_test["dp-be-yt01-insightsWorkspace"]: Read complete after 1s [id=/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-yt01-rg/providers/Microsoft.OperationalInsights/workspaces/dp-be-yt01-insightsWorkspace]
data.azurerm_monitor_data_collection_rule.prometheus: Read complete after 1s [id=/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/MA_k6tests-amw_norwayeast_managed/providers/Microsoft.Insights/dataCollectionRules/k6tests-amw]
data.azurerm_log_analytics_workspace.dp_law_prod: Read complete after 1s [id=/subscriptions/c595f787-450d-4c57-84fa-abc5f95d5459/resourceGroups/dp-be-prod-rg/providers/Microsoft.OperationalInsights/workspaces/dp-be-prod-insightsWorkspace]
data.azurerm_resource_group.rg_dp_stag: Read complete after 1s [id=/subscriptions/e4926efc-0577-47b3-9c3d-757925630eca/resourceGroups/dp-be-staging-rg]
data.azurerm_log_analytics_workspace.dp_law_stag: Reading...
data.azurerm_log_analytics_workspace.dp_law_stag: Read complete after 1s [id=/subscriptions/e4926efc-0577-47b3-9c3d-757925630eca/resourceGroups/dp-be-staging-rg/providers/Microsoft.OperationalInsights/workspaces/dp-be-staging-insightsWorkspace]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # azurerm_kubernetes_cluster_node_pool.spot will be updated in-place
  ~ resource "azurerm_kubernetes_cluster_node_pool" "spot" {
        id                            = "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/k6tests-rg/providers/Microsoft.ContainerService/managedClusters/k6tests-cluster/agentPools/spot"
      ~ max_count                     = 10 -> 1
      ~ min_count                     = 1 -> 0
        name                          = "spot"
      ~ node_count                    = 1 -> 0
        tags                          = {}
        # (28 unchanged attributes hidden)
    }

  # azurerm_role_assignment.monitoring_reader_rg_dp_prod must be replaced
-/+ resource "azurerm_role_assignment" "monitoring_reader_rg_dp_prod" {
      + condition_version                      = (known after apply)
      ~ id                                     = "/subscriptions/c595f787-450d-4c57-84fa-abc5f95d5459/resourceGroups/dp-be-prod-rg/providers/Microsoft.Authorization/roleAssignments/82b2a499-e8bf-09e9-5ea1-88ab810669ee" -> (known after apply)
      ~ name                                   = "82b2a499-e8bf-09e9-5ea1-88ab810669ee" -> (known after apply)
      ~ principal_type                         = "ServicePrincipal" -> (known after apply)
      ~ role_definition_id                     = "/subscriptions/c595f787-450d-4c57-84fa-abc5f95d5459/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" -> "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" # forces replacement
      ~ role_definition_name                   = "Monitoring Reader" -> (known after apply)
        # (6 unchanged attributes hidden)
    }

  # azurerm_role_assignment.monitoring_reader_rg_dp_stag must be replaced
-/+ resource "azurerm_role_assignment" "monitoring_reader_rg_dp_stag" {
      + condition_version                      = (known after apply)
      ~ id                                     = "/subscriptions/e4926efc-0577-47b3-9c3d-757925630eca/resourceGroups/dp-be-staging-rg/providers/Microsoft.Authorization/roleAssignments/e3aa09e6-42e8-ddfe-7f5e-b5dedda8ebfc" -> (known after apply)
      ~ name                                   = "e3aa09e6-42e8-ddfe-7f5e-b5dedda8ebfc" -> (known after apply)
      ~ principal_type                         = "ServicePrincipal" -> (known after apply)
      ~ role_definition_id                     = "/subscriptions/e4926efc-0577-47b3-9c3d-757925630eca/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" -> "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" # forces replacement
      ~ role_definition_name                   = "Monitoring Reader" -> (known after apply)
        # (6 unchanged attributes hidden)
    }

  # azurerm_role_assignment.monitoring_reader_rg_dp_test["dp-be-test-rg"] must be replaced
-/+ resource "azurerm_role_assignment" "monitoring_reader_rg_dp_test" {
      + condition_version                      = (known after apply)
      ~ id                                     = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-test-rg/providers/Microsoft.Authorization/roleAssignments/3eb38b43-62d1-7c1f-7646-f370831e86b3" -> (known after apply)
      ~ name                                   = "3eb38b43-62d1-7c1f-7646-f370831e86b3" -> (known after apply)
      ~ principal_type                         = "ServicePrincipal" -> (known after apply)
      ~ role_definition_id                     = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" -> "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" # forces replacement
      ~ role_definition_name                   = "Monitoring Reader" -> (known after apply)
        # (6 unchanged attributes hidden)
    }

  # azurerm_role_assignment.monitoring_reader_rg_dp_test["dp-be-yt01-rg"] must be replaced
-/+ resource "azurerm_role_assignment" "monitoring_reader_rg_dp_test" {
      + condition_version                      = (known after apply)
      ~ id                                     = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/resourceGroups/dp-be-yt01-rg/providers/Microsoft.Authorization/roleAssignments/3efaf594-a829-fc97-53e3-c5332428c3fe" -> (known after apply)
      ~ name                                   = "3efaf594-a829-fc97-53e3-c5332428c3fe" -> (known after apply)
      ~ principal_type                         = "ServicePrincipal" -> (known after apply)
      ~ role_definition_id                     = "/subscriptions/8a353de8-d81d-468d-a40d-f3574b6bb3f4/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" -> "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/providers/Microsoft.Authorization/roleDefinitions/43d0d8ad-25c7-4714-9337-8ba259a9fe05" # forces replacement
      ~ role_definition_name                   = "Monitoring Reader" -> (known after apply)
        # (6 unchanged attributes hidden)
    }

  # kubernetes_cluster_role_v1.sp_access will be updated in-place
  ~ resource "kubernetes_cluster_role_v1" "sp_access" {
        id = "github-sp-access"

      ~ rule {
          ~ verbs             = [
                # (1 unchanged element hidden)
                "update",
              + "get",
                "watch",
                "delete",
              - "get",
            ]
            # (4 unchanged attributes hidden)
        }

        # (5 unchanged blocks hidden)
    }

Plan: 4 to add, 2 to change, 4 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: tfplan.out

To perform exactly these actions, run the following command to apply:
    terraform apply "tfplan.out"
Releasing state lock. This may take a few moments...

Context Values
Pusher @monteiro-renato
Action push
Working Directory ./infrastructure/adminservices-test/altinn-monitor-test-rg
State File github.com/altinn/altinn-platform/environments/test/altinn-monitor-test-rg.tfstate
Plan File github.com_altinn_altinn-platform_environments_test_altinn-monitor-test-rg.tfstate.tfplan

@monteiro-renato monteiro-renato merged commit d37e379 into main Jan 22, 2025
8 checks passed
@monteiro-renato monteiro-renato deleted the fix-tweak-sp-permissions branch January 22, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants