Skip to content

How to create federated identities via Terraform without a circular dependency? #677

@chadlwilson

Description

@chadlwilson

I use this provider via GitHub actions to source control (almost) all configuration for a tailnet.

As a result, I need to

  • initially manually set up a federated identity for use by the provider with a set of "config write" privileged permissions.
  • this Terraform then creates another, lower privilege, federated identity for GHA workload federation (potentially via different repos/workflows). This identity only has auth_keys and device:core:read privileges for a given tag to support ephemeral device registration on the tailnet, similar to:
    resource "tailscale_federated_identity" "ephemeral_device_federated_identity" {
      description = "GitHub Actions Ephemeral Device Registration"
      scopes      = ["auth_keys", "devices:core:read"]
      tags        = ["tag:ephemeral"]
      issuer      = "https://token.actions.githubusercontent.com"
      subject     = "repo:my-org/my-repo:ref:refs/heads/master" # Only allow token to be generated off master
    }

The problem here is a chicken-vs-egg type of problem on permissions and tag:ephemeral.

  1. I only seem to be able to use the "privileged" federated identity to create/edit the "low privilege" federated identity with the auth_keys scope if the Terraform identity also has the auth_keys scope.
  2. Creating/editing this scope seems to require the relevant tag tag:ephemeral to already exist
  3. Tags are part of Access Controls, and my access controls are supposed to be "externally managed" by Terraform.
  4. So now the tag is both "needs to be manually created" and "should be externally controlled" at the same time.
flowchart LR
  D[Tailscale Terraform\nAccess Controls config creation]
  E[Tailscale Terraform\nFederated Identity]
  A[Tailscale low privilege\nEphemeral Device\nFederated Identity creation]
  B[auth_keys scope]
  C[tag:ephemeral created]


  A -->|requires| B
  A -->|requires| E
  B -->|requires| C
  C -->|requires| D
  D -->|requires| E
  E -->|requires| B
Loading

Perhaps this is just intrinsic to the permissions model and not specific to the provider; but I wonder if there are scopes/techniques available to break the circular dependency on creation of the tag:ephemeral tag here while still using two different federated identities.

tailscale_federated_identity.ephemeral_device_federated_identity: Modifying... [id=***]
╷
│ Error: Failed to update federated identity
│ 
│   with tailscale_federated_identity.ephemeral_device_federated_identity,
│   on tailscale.tf line 55, in resource "tailscale_federated_identity" "ephemeral_device_federated_identity":
│   55: resource "tailscale_federated_identity" "ephemeral_device_federated_identity" {
│ 
│ actor cannot set scopes: [auth_keys devices:core:read] (403)
╵

Ideally if intending to use Terraform to manage ones ACLs, and other federated identities - it'd be better to not have this circular dependency on tag creation via the auth_keys scope ... somehow. Is there a way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions