Skip to main content

tharsis_managed_identity_access_rule

Defines and manages a managed identity access rule.

Example Usage​

resource "tharsis_managed_identity_access_rule" "eligible_principals" {
managed_identity_id = tharsis_managed_identity.aws.id
type = "eligible_principals"
run_stage = "plan"
allowed_service_account_ids = [tharsis_service_account.this.id]
}

resource "tharsis_managed_identity_access_rule" "module_attestation" {
managed_identity_id = tharsis_managed_identity.aws.id
type = "module_attestation"
run_stage = "apply"
verify_state_lineage = true

module_attestation_policies = [
{
public_key = file("${path.module}/attestation-key.pem")
predicate_type = "https://slsa.dev/provenance/v1"
}
]
}

Behavior​

  • By default, anyone with deployer access to a managed identity can assume it. Access rules restrict this.
  • Rules of the same type are combined with OR logic: one match is enough. Rules of different types are combined with AND logic: at least one rule of each type must match.
  • A rule applies to one run stage, plan or apply. If no rule exists for a stage, any principal may assume the identity for that stage.

Rule types​

  • eligible_principals limits use to specific users, teams, or service accounts, given by allowed_user_ids, allowed_team_ids, and allowed_service_account_ids.
  • module_attestation requires the root module to carry an attestation signed with the public key of one of the module_attestation_policies. This is supported only for modules in the Tharsis registry.

State lineage​

When verify_state_lineage is true, the rule also verifies that the workspace's current state came from the same module source. It defaults to false.

Schema​

Required​

  • managed_identity_id (String) The ID or TRN of the connected managed identity.
  • run_stage (String) Type of job, plan or apply.
  • type (String) Type of access rule: eligible_principals or module_attestation.

Optional​

  • allowed_service_account_ids (Set of String) List of service account IDs allowed to use the managed identity associated with this rule.
  • allowed_service_accounts (Set of String, Deprecated) List of resource paths of service accounts allowed to use the managed identity associated with this rule.
  • allowed_team_ids (Set of String) List of team IDs allowed to use the managed identity associated with this rule.
  • allowed_teams (Set of String, Deprecated) List of names of teams allowed to use the managed identity associated with this rule.
  • allowed_user_ids (Set of String) List of user IDs allowed to use the managed identity associated with this rule.
  • allowed_users (Set of String, Deprecated) List of usernames allowed to use the managed identity associated with this rule.
  • module_attestation_policies (Attributes List) Used to verify that a module has an in-toto attestation that is signed with the specified public key and an optional predicate type. (see below for nested schema)
  • verify_state_lineage (Boolean) Whether to verify that the workspace's current state is from the same module source, default is false.

Read-Only​

  • id (String) String identifier of the access rule.

Nested Schema for module_attestation_policies​

Required:

  • public_key (String) Public key in PEM format for this attestation policy.

Optional:

  • predicate_type (String) Optional predicate type for this attestation policy.

Import​

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the import block can be used with the id attribute, for example:

# An access rule has no human-readable name, so it is imported by its ID, shown
# by the "id" attribute or in the Tharsis UI.
import {
to = tharsis_managed_identity_access_rule.eligible_principals
id = "<access-rule-id>"
}

# A TRN also works, but its last segment is the same rule ID, so it offers no
# advantage: "trn:managed_identity_access_rule:my-group/my-aws-identity/<access-rule-id>".