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

Cognito UserPoolClient resource creation fails with internal operator error #807

Closed
mdundek opened this issue Aug 2, 2023 · 6 comments · Fixed by #1021
Closed

Cognito UserPoolClient resource creation fails with internal operator error #807

mdundek opened this issue Aug 2, 2023 · 6 comments · Fixed by #1021
Labels

Comments

@mdundek
Copy link

mdundek commented Aug 2, 2023

What happened?

Creating a Cognito UserPoolClient for a UserPool fails. The resource passes validation successfully when being applied, but the client is never created. When checking the status of the resource, I get the following result:

apiVersion: v1
items:
- apiVersion: cognitoidp.aws.upbound.io/v1beta1
  kind: UserPoolClient
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"cognitoidp.aws.upbound.io/v1beta1","kind":"UserPoolClient","metadata":{"annotations":{},"labels":{"msi.upbound.io/user-pool-client-name":"cp-msi-test-user-pool-client"},"name":"cp-msi-test-user-pool-client"},"spec":{"forProvider":{"allowedOauthFlowsUserPoolClient":true,"allowedOauthScopes":["email","openid","profile"],"callbackUrls":["http://localhost:8000"],"explicitAuthFlows":["ALLOW_REFRESH_TOKEN_AUTH","ALLOW_CUSTOM_AUTH","ALLOW_USER_SRP_AUTH"],"generateSecret":false,"idTokenValidity":1,"name":"cp-msi-test-user-pool-client","refreshTokenValidity":2,"region":"us-east-1","userPoolIdSelector":{"matchLabels":{"msi.upbound.io/userpool-name":"cp-msi-test"}}},"providerConfigRef":{"name":"msi-aws-dev"}}}
    creationTimestamp: "2023-08-02T18:06:35Z"
    generation: 3
    labels:
      msi.upbound.io/user-pool-client-name: cp-msi-test-user-pool-client
    name: cp-msi-test-user-pool-client
    resourceVersion: "77568032"
    uid: 72ac8279-8b72-4974-9463-f31f136d89ac
  spec:
    deletionPolicy: Delete
    forProvider:
      allowedOauthFlowsUserPoolClient: true
      allowedOauthScopes:
      - email
      - openid
      - profile
      callbackUrls:
      - http://localhost:8000
      explicitAuthFlows:
      - ALLOW_REFRESH_TOKEN_AUTH
      - ALLOW_CUSTOM_AUTH
      - ALLOW_USER_SRP_AUTH
      generateSecret: false
      idTokenValidity: 1
      name: cp-msi-test-user-pool-client
      refreshTokenValidity: 2
      region: us-east-1
      userPoolId: us-east-1_S4gvrPh9H
      userPoolIdRef:
        name: cp-msi-test
      userPoolIdSelector:
        matchLabels:
          msi.upbound.io/userpool-name: cp-msi-test
    managementPolicy: FullControl
    providerConfigRef:
      name: msi-aws-dev
  status:
    atProvider: {}
    conditions:
    - lastTransitionTime: "2023-08-02T18:07:28Z"
      message: |
        observe failed: cannot run refresh: refresh failed: reading Amazon Cognito IDP (Identity Provider) User Pool Client (): InvalidParameter: 1 validation error(s) found.
        - minimum field size of 1, DescribeUserPoolClientInput.ClientId.
      reason: ReconcileError
      status: "False"
      type: Synced
kind: List
metadata:
  resourceVersion: ""

How can we reproduce it?

Create a UserPool:

apiVersion: cognitoidp.aws.upbound.io/v1beta1
kind: UserPool
metadata:
  labels:
    test.upbound.io/userpool-name: my-user-pool
  name: my-user-pool
spec:
  forProvider:
    name: my-user-pool
    autoVerifiedAttributes:
    - email
    usernameAttributes:
    - email
    passwordPolicy:
    - minimumLength: 6
      requireNumbers: false
      requireSymbols: false
      requireUppercase: false
      requireLowercase: false
    region: us-east-1
  providerConfigRef:
    name: my-aws-provider

Then create the UserPoolClient:

apiVersion: cognitoidp.aws.upbound.io/v1beta1
kind: UserPoolClient
metadata:
  labels:
    test.upbound.io/user-pool-client-name: my-user-pool-client
  name: my-user-pool-client
spec:
  forProvider:
    name: my-user-pool-client
    region: us-east-1
    userPoolIdSelector:
      matchLabels:
        test.upbound.io/userpool-name: my-user-pool
    explicitAuthFlows:
    - ALLOW_REFRESH_TOKEN_AUTH
    - ALLOW_CUSTOM_AUTH
    - ALLOW_USER_SRP_AUTH
    generateSecret: false
    callbackUrls:
    - http://localhost:8000
    allowedOauthFlowsUserPoolClient: true
    allowedOauthScopes:
    - email
    - openid
    - profile
    refreshTokenValidity: 2
    idTokenValidity: 1
  providerConfigRef:
    name: my-aws-provider

Then check UserPoolStatus:

kubectl describe userpoolclient my-user-pool-client

Which prints the error mentioned in the problem description above.

When checking the AWS console for the UserPool, the UserPoolClient is never created.

What environment did it happen in?

  • Crossplane Version: 1.13.1
  • Provider Version: upbound/provider-aws-cognitoidp@v0.36.0
  • Kubernetes Version: v1.25.4
  • Kubernetes Distribution: GKE - v1.25.10-gke.1200
@mdundek mdundek added bug Something isn't working needs:triage labels Aug 2, 2023
@turkenf
Copy link
Collaborator

turkenf commented Aug 7, 2023

Hi @mdundek,

Thank you for raising this issue. I checked your examples and there are a few missing, the example below is working successfully, can you try it, please?

apiVersion: cognitoidp.aws.upbound.io/v1beta1
kind: UserPoolClient
metadata:
  labels:
    test.upbound.io/user-pool-client-name: my-user-pool-client
  name: my-user-pool-client
spec:
  forProvider:
    name: my_user_pool_client
    region: us-east-1
    userPoolIdSelector:
      matchLabels:
        test.upbound.io/userpool-name: my-user-pool
    allowedOauthFlows:
    - code
    explicitAuthFlows:
    - ALLOW_REFRESH_TOKEN_AUTH
    - ALLOW_CUSTOM_AUTH
    - ALLOW_USER_SRP_AUTH
    generateSecret: false
    callbackUrls:
    - http://localhost:8000
    allowedOauthFlowsUserPoolClient: true
    allowedOauthScopes:
    - email
    - openid
    - profile
    refreshTokenValidity: 2
    idTokenValidity: 1

difference from your example:

name =>  use "_" instead of "-" in between
allowedOauthFlows => allowedOAuthFlows and allowedOAuthScopes are required if user pool client is allowed to use OAuth flows

@mdundek
Copy link
Author

mdundek commented Aug 11, 2023

Hello @turkenf, thank for your reply. I have integrated your suggestions, unfortunately without success. Here is what I user in my test:

apiVersion: cognitoidp.aws.upbound.io/v1beta1
kind: UserPool
metadata:
  labels:
    test.upbound.io/userpool-name: my-user-pool
  name: my-user-pool
spec:
  forProvider:
    name: my-user-pool
    autoVerifiedAttributes:
    - email
    usernameAttributes:
    - email
    passwordPolicy:
    - minimumLength: 6
      requireNumbers: false
      requireSymbols: false
      requireUppercase: false
      requireLowercase: false
    region: us-east-1
  providerConfigRef:
    name: test-aws-dev
---
apiVersion: cognitoidp.aws.upbound.io/v1beta1
kind: UserPoolClient
metadata:
  labels:
    test.upbound.io/user-pool-client-name: my-user-pool-client
  name: my-user-pool-client
spec:
  forProvider:
    name: my_user_pool_client
    region: us-east-1
    userPoolIdSelector:
      matchLabels:
        test.upbound.io/userpool-name: my-user-pool
    allowedOauthFlows:
    - code
    explicitAuthFlows:
    - ALLOW_REFRESH_TOKEN_AUTH
    - ALLOW_CUSTOM_AUTH
    - ALLOW_USER_SRP_AUTH
    generateSecret: false
    callbackUrls:
    - http://localhost:8000
    allowedOauthFlowsUserPoolClient: true
    allowedOauthScopes:
    - email
    - openid
    - profile
    refreshTokenValidity: 2
    idTokenValidity: 1
  providerConfigRef:
    name: test-aws-dev

And here is the result of my describe command for the UserPoolClient resource:

Name:         my-user-pool-client
Namespace:    
Labels:       test.upbound.io/user-pool-client-name=my-user-pool-client
Annotations:  <none>
API Version:  cognitoidp.aws.upbound.io/v1beta1
Kind:         UserPoolClient
Metadata:
  Creation Timestamp:  2023-08-11T14:37:26Z
  Generation:          2
  Managed Fields:
    API Version:  cognitoidp.aws.upbound.io/v1beta1
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .:
          f:kubectl.kubernetes.io/last-applied-configuration:
        f:labels:
          .:
          f:test.upbound.io/user-pool-client-name:
      f:spec:
        .:
        f:deletionPolicy:
        f:forProvider:
          .:
          f:allowedOauthFlows:
          f:allowedOauthFlowsUserPoolClient:
          f:allowedOauthScopes:
          f:callbackUrls:
          f:explicitAuthFlows:
          f:generateSecret:
          f:idTokenValidity:
          f:name:
          f:refreshTokenValidity:
          f:region:
          f:userPoolIdSelector:
            .:
            f:matchLabels:
              .:
              f:test.upbound.io/userpool-name:
        f:managementPolicy:
        f:providerConfigRef:
          .:
          f:name:
    Manager:      kubectl-client-side-apply
    Operation:    Update
    Time:         2023-08-11T14:37:26Z
    API Version:  cognitoidp.aws.upbound.io/v1beta1
    Fields Type:  FieldsV1
    fieldsV1:
      f:spec:
        f:forProvider:
          f:userPoolId:
          f:userPoolIdRef:
            .:
            f:name:
    Manager:      provider
    Operation:    Update
    Time:         2023-08-11T14:37:39Z
    API Version:  cognitoidp.aws.upbound.io/v1beta1
    Fields Type:  FieldsV1
    fieldsV1:
      f:status:
        .:
        f:atProvider:
        f:conditions:
    Manager:         provider
    Operation:       Update
    Subresource:     status
    Time:            2023-08-11T14:37:43Z
  Resource Version:  86027221
  UID:               0c107bfa-e99d-4f9a-a7c2-fde9cb18d72c
Spec:
  Deletion Policy:  Delete
  For Provider:
    Allowed Oauth Flows:
      code
    Allowed Oauth Flows User Pool Client:  true
    Allowed Oauth Scopes:
      email
      openid
      profile
    Callback Urls:
      http://localhost:8000
    Explicit Auth Flows:
      ALLOW_REFRESH_TOKEN_AUTH
      ALLOW_CUSTOM_AUTH
      ALLOW_USER_SRP_AUTH
    Generate Secret:         false
    Id Token Validity:       1
    Name:                    my_user_pool_client
    Refresh Token Validity:  2
    Region:                  us-east-1
    User Pool Id:            us-east-1_UQlcsuSNl
    User Pool Id Ref:
      Name:  my-user-pool
    User Pool Id Selector:
      Match Labels:
        test.upbound.io/userpool-name:  my-user-pool
  Management Policy:                    FullControl
  Provider Config Ref:
    Name:  msi-aws-dev
Status:
  At Provider:
  Conditions:
    Last Transition Time:  2023-08-11T14:37:43Z
    Message:               observe failed: cannot run refresh: refresh failed: reading Amazon Cognito IDP (Identity Provider) User Pool Client (): InvalidParameter: 1 validation error(s) found.
- minimum field size of 1, DescribeUserPoolClientInput.ClientId.

    Reason:  ReconcileError
    Status:  False
    Type:    Synced
Events:
  Type     Reason                           Age                    From                                                            Message
  ----     ------                           ----                   ----                                                            -------
  Warning  CannotResolveResourceReferences  6m53s (x4 over 6m58s)  managed/cognitoidp.aws.upbound.io/v1beta1, kind=userpoolclient  cannot resolve references: mg.Spec.ForProvider.UserPoolID: referenced field was empty (referenced resource may not yet be ready)
  Warning  CannotObserveExternalResource    6s (x9 over 6m41s)     managed/cognitoidp.aws.upbound.io/v1beta1, kind=userpoolclient  cannot run refresh: refresh failed: reading Amazon Cognito IDP (Identity Provider) User Pool Client (): InvalidParameter: 1 validation error(s) found.
- minimum field size of 1, DescribeUserPoolClientInput.ClientId.

NOTE: The UserPool is healthy.

@turkenf
Copy link
Collaborator

turkenf commented Aug 11, 2023

Which provider version are you using?

@mdundek
Copy link
Author

mdundek commented Aug 11, 2023

I am using xpkg.upbound.io/upbound/provider-aws:v0.37.0

@turkenf
Copy link
Collaborator

turkenf commented Aug 11, 2023

I just tried the example you gave and it works fine in v0.38.0, there may be a problem with your environment, you can check following:

spec:
  deletionPolicy: Delete
  forProvider:
    allowedOauthFlows:
    - code
    allowedOauthFlowsUserPoolClient: true
    allowedOauthScopes:
    - email
    - openid
    - profile
    authSessionValidity: 3
    callbackUrls:
    - http://localhost:8000
    enableTokenRevocation: true
    explicitAuthFlows:
    - ALLOW_REFRESH_TOKEN_AUTH
    - ALLOW_CUSTOM_AUTH
    - ALLOW_USER_SRP_AUTH
    generateSecret: false
    idTokenValidity: 1
    name: my_user_pool_client
    refreshTokenValidity: 2
    region: us-east-1
    userPoolId: us-east-1_7jxJja2RN
    userPoolIdRef:
      name: my-user-pool
    userPoolIdSelector:
      matchLabels:
        test.upbound.io/userpool-name: my-user-pool
  initProvider: {}
  managementPolicies:
  - '*'
  providerConfigRef:
    name: default
status:
  atProvider:
    accessTokenValidity: 0
    allowedOauthFlows:
    - code
    allowedOauthFlowsUserPoolClient: true
    allowedOauthScopes:
    - email
    - openid
    - profile
    authSessionValidity: 3
    callbackUrls:
    - http://localhost:8000
    defaultRedirectUri: ""
    enablePropagateAdditionalUserContextData: false
    enableTokenRevocation: true
    explicitAuthFlows:
    - ALLOW_CUSTOM_AUTH
    - ALLOW_REFRESH_TOKEN_AUTH
    - ALLOW_USER_SRP_AUTH
    generateSecret: false
    id: 1hihktvtbl3seo2rj92g3l4qp7
    idTokenValidity: 1
    name: my_user_pool_client
    preventUserExistenceErrors: ""
    refreshTokenValidity: 2
    userPoolId: us-east-1_7jxJja2RN
  conditions:
  - lastTransitionTime: "2023-08-11T19:08:20Z"
    reason: ReconcileSuccess
    status: "True"
    type: Synced
  - lastTransitionTime: "2023-08-11T19:09:46Z"
    reason: Available
    status: "True"
    type: Ready
  - lastTransitionTime: "2023-08-11T19:08:38Z"
    reason: Success
    status: "True"
    type: LastAsyncOperation
  - lastTransitionTime: "2023-08-11T19:08:38Z"
    reason: Finished
    status: "True"
    type: AsyncOperation

@mbbush
Copy link
Collaborator

mbbush commented Dec 22, 2023

This is still an issue in the latest version of the provider. I believe #1021 will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants