okta / terraform-provider-okta

A Terraform provider to manage Okta resources, enabling infrastructure-as-code provisioning and management of users, groups, applications, and other Okta objects.
https://registry.terraform.io/providers/okta/okta
Mozilla Public License 2.0
258 stars 208 forks source link

Failed to change OIDC identity provider's status when destroying/re-applying multiple times an IDP #1042

Closed Cylock closed 1 year ago

Cylock commented 2 years ago

Community Note

Terraform Version

v1.1.6

General description

Hello,

I'm trying to create an OIDC Identity Provider resource to my Okta developer instance.

At terraform apply it creates the remote object but an error pops up during the process:

image

Debugging

I have enabled debug logs for terraform and seems the culprit for the error above is this following call to /api/v1/idps/.../lifecycle/activate

-----------------------------------------------------: timestamp=2022-04-01T12:06:53.368+0300
2022-04-01T12:06:53.386+0300 [DEBUG] provider.terraform-provider-okta_v3.22.1.exe: 2022/04/01 12:06:53 [DEBUG] performing request: method=POST url=https://dev-43724224.okta.com/api/v1/idps/0oa4gx83jcT8RXqeO5d7/lifecycle/activate
2022-04-01T12:06:53.386+0300 [INFO]  provider.terraform-provider-okta_v3.22.1.exe: 2022/04/01 12:06:53 [DEBUG] Okta API Request Details:
---[ REQUEST ]---------------------------------------
POST /api/v1/idps/0oa4gx83jcT8RXqeO5d7/lifecycle/activate HTTP/1.1
Host: dev-43724224.okta.com
User-Agent: okta-sdk-golang/2.9.2 golang/go1.17.7 windows/amd64 okta-terraform/3.22.1
Content-Length: 0
Accept: application/json
Authorization: SSWS 00bMN_0ev5BY99QU1VwImYeFv8lpa3ZajwdkrpJxkn
Accept-Encoding: gzip

-----------------------------------------------------: timestamp=2022-04-01T12:06:53.370+0300
2022-04-01T12:06:53.596+0300 [INFO]  provider.terraform-provider-okta_v3.22.1.exe: 2022/04/01 12:06:53 [DEBUG] Okta API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 403 Forbidden
Cache-Control: no-cache, no-store
Content-Security-Policy: default-src 'self' dev-43724224.okta.com *.oktacdn.com; connect-src 'self' dev-43724224.okta.com dev-43724224-admin.okta.com *.oktacdn.com *.mixpanel.com *.mapbox.com app.pendo.io data.pendo.io pendo-static-5634101834153984.storage.googleapis.com https://oinmanager.okta.com data:; script-src 'unsafe-inline' 'unsafe-eval' 'self' dev-43724224.okta.com *.oktacdn.com; style-src 'unsafe-inline' 'self' dev-43724224.okta.com *.oktacdn.com app.pendo.io cdn.pendo.io pendo-static-5634101834153984.storage.googleapis.com; frame-src 'self' dev-43724224.okta.com 
dev-43724224-admin.okta.com login.okta.com; img-src 'self' dev-43724224.okta.com *.oktacdn.com *.tiles.mapbox.com *.mapbox.com app.pendo.io data.pendo.io cdn.pendo.io pendo-static-5634101834153984.storage.googleapis.com data: blob:; font-src 'self' dev-43724224.okta.com data: *.oktacdn.com fonts.gstatic.com; frame-ancestors 'self'
Content-Type: application/json
Date: Fri, 01 Apr 2022 09:06:52 GMT
Expect-Ct: report-uri="https://oktaexpectct.report-uri.com/r/t/ct/reportOnly", max-age=0
Expires: 0
P3p: CP="HONK"
Pragma: no-cache
Public-Key-Pins-Report-Only: pin-sha256="r5EfzZxQVvQpKo3AgYRaT7X2bDO/kj3ACwmxfdT2zt8="; pin-sha256="MaqlcUgk2mvY/RFSGeSwBRkI+rZ6/dxe/DuQfBT/vnQ="; pin-sha256="72G5IEvDEWn+EThf3qjR7/bQSWaS2ZSLqolhnO6iyJI="; pin-sha256="rrV6CLCCvqnk89gWibYT0JO6fNQ8cCit7GGoiVTjCOg="; max-age=60; report-uri="https://okta.report-uri.com/r/default/hpkp/reportOnly"
Server: nginx
Set-Cookie: sid=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: autolaunch_triggered=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: JSESSIONID=1D5DA85E1570C86DDEA3946F83FF7B0E; Path=/; Secure; HttpOnly
Strict-Transport-Security: max-age=315360000; includeSubDomains
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Okta-Request-Id: YkbArPytjZUca5xB7TUbaQAAAfM
X-Rate-Limit-Limit: 100
X-Rate-Limit-Remaining: 93
X-Rate-Limit-Reset: 1648804058
X-Xss-Protection: 0

{
 "errorCode": "E0000143",
 "errorSummary": "App instance operation not allowed.",
 "errorLink": "E0000143",
 "errorId": "oaeyEnpXDYLQsC_2VUkEVVbWQ",
 "errorCauses": [
  {
   "errorSummary": "The requested action cannot be supported for this application."
  }
 ]
}

Attempts to solve

  1. Set status = "ACTIVE" explicit in the resource - the documentation states that active is by default
  2. Applied, deactivated, deleted from UI and tried to re-apply again.

Affected Resource(s)

Terraform Configuration Files

# okta_idp_oidc.BindID:
resource "okta_idp_oidc" "BindID" {
  account_link_action   = "AUTO"
  user_info_url         = var.bindid_user_info_url
  token_url             = var.bindid_token_url
  jwks_url              = var.bindid_jwks_url
  issuer_url            = var.bindid_issuer_url
  client_secret         = var.bindid_client_secret
  authorization_url     = var.bindid_authorization_url
  authorization_binding = "HTTP-REDIRECT"
  client_id             = "efg456"
  deprovisioned_action  = "NONE"
  groups_action         = "NONE"
  groups_assignment     = []
  groups_filter         = []
  issuer_mode           = "ORG_URL"
  jwks_binding          = "HTTP-REDIRECT"
  max_clock_skew        = 0
  name                  = "BindID"
  profile_master        = true
  provisioning_action   = "AUTO"
  scopes = [
    "email",
    "openid",
  ]
  subject_match_type = "USERNAME"
  suspended_action   = "NONE"
  token_binding      = "HTTP-POST"
  user_info_binding  = "HTTP-REDIRECT"
  username_template  = "idpuser.email"
}

Expected Behavior

Create the remote object cleanly after each destroy and apply without any issues and track it.

Actual Behavior

It creates the remote object, but because there is an error it taints the resource mapped to it in the terraform.tfstate.

There is an inconsistent behavior: In a few tests running multiple terraform destroy / terraform apply, sometimes the resource is created without any errors, other instances it displays the errors above.

Seems strange to be able to send the same requests to /lifecycle/activate and receive a 200 once and after to get a 403 for a destroyed and re-applied resource.

Throwing a wild guess: I would assume it could be a token from the client side which is a 1 time use and expires but somewhere down the line it is stored and that's why on follow up requests it shows unauthorized.

Steps to Reproduce

  1. terraform apply/destroy multiple times

Important Factoids

Working with a free Okta developer account.

References

monde commented 2 years ago

Hi @Cylock , I appreciate all of the debugging details, I will look into this.

okta-mikeb commented 2 years ago

@monde - I am seeing the same behavior for both the SAML and OIDC IdP resources. Sometimes the plan/apply works, sometimes I get the same error with "App instance operation not allowed".

In addition to that, I have also tried to manually activate the IdP in the UI after being created with Terraform and receive the same error as above in the Network tab of Developer tools.

monde commented 2 years ago

@okta-mikeb thanks for the additional details.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

RomanVlasenko commented 2 years ago

@monde is there any update or workaround for this? I'm having the same issue with OIDC resource. At the moment it is unusable. Even if I create resource manually and import to terraform - it becomes deactivated after apply and further activation is not possible, UI would throw the same error as @Cylock has mentioned.

monde commented 2 years ago

Okta internal reference: https://oktainc.atlassian.net/browse/OKTA-544480

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

monde commented 1 year ago

@Cylock @okta-mikeb are you all still experiencing this? The issue was reported nearly a year ago so it might have just been stability issues in the Okta service itself.

I did receive one 500 error while fiddling around working up my example. Otherwise it was all 200s doing apply/destroy in a loop.

$ for i in {1..10}; do
tf apply -auto-approve 2>&1 > /dev/null
if [ $? -ne 0 ] ; then echo "fail apply"; else echo "pass apply"; fi
tf destroy -auto-approve 2>&1 > /dev/null
if [ $? -ne 0 ] ; then echo "fail destroy"; else echo "pass destroy"; fi
done
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy
pass apply
pass destroy

this is my tf code based off @Cylock's example with the VARs hack out

terraform {
  required_providers {
    okta = {
      source = "okta/okta"
    }
  }
}

resource "okta_idp_oidc" "BindID" {
  account_link_action   = "AUTO"
  #user_info_url         = var.bindid_user_info_url
  user_info_url         = "https://idp.example.com/userinfo"
  #token_url             = var.bindid_token_url
  token_url             = "https://idp.example.com/token"
  #jwks_url              = var.bindid_jwks_url
  jwks_url              = "https://idp.example.com/keys"
  #issuer_url            = var.bindid_issuer_url
  issuer_url            = "https://id.example.com"
  #client_secret         = var.bindid_client_secret
  client_secret         = "01234567890123456789012345678901"
  #authorization_url     = var.bindid_authorization_url
  authorization_url     = "https://idp.example.com/authorize"
  authorization_binding = "HTTP-REDIRECT"
  client_id             = "efg456"
  deprovisioned_action  = "NONE"
  groups_action         = "NONE"
  groups_assignment     = []
  groups_filter         = []
  issuer_mode           = "ORG_URL"
  jwks_binding          = "HTTP-REDIRECT"
  max_clock_skew        = 0
  name                  = "BindID"
  profile_master        = true
  provisioning_action   = "AUTO"
  scopes = [
    "email",
    "openid",
  ]
  subject_match_type = "USERNAME"
  suspended_action   = "NONE"
  token_binding      = "HTTP-POST"
  user_info_binding  = "HTTP-REDIRECT"
  username_template  = "idpuser.email"
}
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days