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

Bug in validation logic that is checking supported service credential role values #817

Open
ocofaigh opened this issue Jan 17, 2025 · 4 comments
Assignees
Labels
bug 🐞 Something isn't working internal-synced

Comments

@ocofaigh
Copy link
Member

A consumer has reported when trying to create a service credential using the role "Object Writer" it fails...

Input:

[
  {
    "secret_group_name": "scc"
    "existing_secret_group": true
    "service_credentials": [
      {
        "secret_name": "scc-cos-service-credentials"
        "service_credentials_source_service_role":  "Object Writer"
        "secret_labels": ["backup-secret"]
        "secret_auto_rotation": true
        "secret_auto_rotation_unit": "day"
        "secret_auto_rotation_interval": 89
        "service_credentials_ttl": 7776000
        "service_credential_secret_description": "sample description"
      }
    ]
  }
]

Fails with this:

Image

The problem is the CRN that is generated has a space in it, and so fails regex check:

Image

ACTIONS:

@shemau
Copy link
Contributor

shemau commented Jan 20, 2025

WIP:

module.secrets_manager_service_credentials[0].module.secrets["cred-2"].ibm_sm_service_credentials_secret.service_credentials_secret[0]: Creating...
╷
│ Error: ---
│ id: terraform-d7812ff8
│ summary: |
│   CreateSecretWithContext failed: Bad request error. [secrets-manager.13037E]
│   {
│       "StatusCode": 400,
│       "Headers": {
│           "Cache-Control": [
│               "no-store, no-cache, must-revalidate, proxy-revalidate,no-cache, max-age=0, no-store"
│           ],
│           "Cf-Cache-Status": [
│               "DYNAMIC"
│           ],
│           "Cf-Ray": [
│               "904fed682c3660f9-LHR"
│           ],
│           "Content-Security-Policy": [
│               "default-src 'none'"
│           ],
│           "Content-Type": [
│               "application/json; charset=utf-8"
│           ],
│           "Correlation-Id": [
│               "f186b827-3167-7b25-0720-08a589780946"
│           ],
│           "Cross-Origin-Resource-Policy": [
│               "same-origin"
│           ],
│           "Date": [
│               "Mon, 20 Jan 2025 14:59:18 GMT"
│           ],
│           "Expires": [
│               "0"
│           ],
│           "Pragma": [
│               "no-cache"
│           ],
│           "Server": [
│               "cloudflare"
│           ],
│           "Strict-Transport-Security": [
│               "max-age=31536000; includeSubDomains; preload"
│           ],
│           "Surrogate-Control": [
│               "no-store"
│           ],
│           "Vary": [
│               "Accept-Encoding"
│           ],
│           "X-Content-Type-Options": [
│               "nosniff"
│           ]
│       },
│       "Result": {
│           "errors": [
│               {
│                   "code": "bad_request",
│                   "message": "Bad request error. [secrets-manager.13037E]",
│                   "more_info": "https://cloud.ibm.com/apidocs/secrets-manager"
│               }
│           ],
│           "status_code": 400,
│           "trace": "f186b827-3167-7b25-0720-08a589780946"
│       },
│       "RawResult": null
│   }
│ severity: error
│ resource: ibm_sm_service_credentials_secret
│ operation: create
│ component:
│   name: github.com/IBM-Cloud/terraform-provider-ibm
│   version: 1.73.0
│ ---
│ 
│ 
│   with module.secrets_manager_service_credentials[0].module.secrets["cred-2"].ibm_sm_service_credentials_secret.service_credentials_secret[0],
│   on .terraform/modules/secrets_manager_service_credentials.secrets/main.tf line 95, in resource "ibm_sm_service_credentials_secret" "service_credentials_secret":
│   95: resource "ibm_sm_service_credentials_secret" "service_credentials_secret" {
│ 
╵

Following code changes to the proposed role name ObjectWriter the CRN looks fine, but there is a subsequent error being investigated.

      + source_service {
          + iam          = (known after apply)
          + resource_key = (known after apply)

          + instance {
              + crn = "crn:v1:bluemix:public:cloud-object-storage:global:a/abac0df06b644a9cabc6e44f55b3880e:24cd9373-68e7-4058-bd0b-5d811cc8db56::"
            }

          + role {
              + crn = "crn:v1:bluemix:public:iam::::serviceRole:ObjectWriter"
            }
        }

@shemau
Copy link
Contributor

shemau commented Jan 20, 2025

When using a space ( + crn = "crn:v1:bluemix:public:iam::::serviceRole:Object Writer") it clearly reports

"│ CreateSecretWithContext failed: Request validation error: doesn't match schema due to: Error at "/source_service/role/crn": string doesn't match the regular expression "^crn:v0-9{8}$""

And reports where the problem is '/source_service/role/crn'.

When not using a space (crn:v1:bluemix:public:iam::::serviceRole:ObjectWriter)

A generic error is reported.

"│ CreateSecretWithContext failed: Bad request error. [secrets-manager.13037E]"

No idea if it passed the CRN check and failed for some other reason or the CRN matches the pattern, but is wrong.

@shemau
Copy link
Contributor

shemau commented Jan 20, 2025

The thread leads to secrets manager secret module at https://github.com/terraform-ibm-modules/terraform-ibm-secrets-manager-secret/blob/main/main.tf#L111

where the role is constructed as:

crn:v1:bluemix:public:iam::::serviceRole:ObjectWriter

whilst the documentation in IAM (https://cloud.ibm.com/iam/roles)

CRN: crn:v1:bluemix:public:cloud-object-storage::::serviceRole:ObjectWriter
Description: As an Object Writer, one can only write objects to a bucket.

crn:v1:bluemix:public:cloud-object-storage::::serviceRole:ObjectWriter

If this is the case, I am not sure that any of our service related roles would work via this module.

@ocofaigh
Copy link
Member Author

ocofaigh commented Jan 22, 2025

As per internal discussions, the action items are:

  1. [terraform-ibm-secrets-manager-secret] Add support to create service specific role
  2. [terraform-ibm-secrets-manager] Add support to create service specific role credentials in the secrets submodule
  3. Continue to ask for the service role in the COS DA but add logic to construct the CRN that will be passed to the secrets module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working internal-synced
Projects
None yet
Development

No branches or pull requests

3 participants