amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

deployment-secrets.json migration causes amplify[hostedUIProviderCreds] must have values error on amplify push

Open pedramp20 opened this issue 6 years ago • 51 comments

After upgrading cli to 4.34.0, the cli forces to move secrets from team-provider-info.json to deployment-secrets.json on amplify push After selecting Yes, it seem like the migration is successful and push works just fine. However, the deployment-secrets.json is never created and on the future pushes, I get the following error:

amplify[hostedUIProviderCreds] must have values

It is due to deletion of the hostedUIProviderCreds from the team-provider-info.

pedramp20 avatar Nov 24 '20 00:11 pedramp20

@pedramp20 I am trying to reproduce this issue, what changes did you make before the second push?

ammarkarachi avatar Nov 24 '20 00:11 ammarkarachi

With the last version on env update

(venv) PS C:\Users\sinap\repo\lookea\influencers-dashboard> amplify status ? Amplify has been upgraded to handle secrets more securely by migrating some values in team-provider-info.json to deployment-secrets.json You can create a back up of the team-provider-info.json file before proceeding. Yes Error updating Cognito resource File at path: 'C:\Users\sinap\repo\lookea\influencers-dashboard\amplify\backend\amplify-meta.json' does not exist Error: File at path: 'C:\Users\sinap\repo\lookea\influencers-dashboard\amplify\backend\amplify-meta.json' does not exist at Function.JSONUtilities.readJson (C:\Users\sinap\scoop\persist\nodejs\bin\node_modules@aws-amplify\cli\node_modules\amplify-cli-core\src\jsonUtilities.ts:25:15) at StateManager.getData (C:\Users\sinap\scoop\persist\nodejs\bin\node_modules@aws-amplify\cli\node_modules\amplify-cli-core\src\state-manager\stateManager.ts:207:32) at StateManager.getMeta (C:\Users\sinap\scoop\persist\nodejs\bin\node_modules@aws-amplify\cli\node_modules\amplify-cli-core\src\state-manager\stateManager.ts:24:23) at AmplifyToolkit.updateamplifyMetaAfterResourceAdd [as _updateamplifyMetaAfterResourceAdd] (C:\Users\sinap\scoop\persist\nodejs\bin\node_modules@aws-amplify\cli\src\extensions\amplify-helpers\update-amplify-meta.ts:78:36) at Object.externalAuthEnable (C:\Users\sinap\scoop\persist\nodejs\bin\node_modules@aws-amplify\cli\node_modules\amplify-category-auth\src\index.js:137:21) at processTicksAndRejections (internal/process/task_queues.js:93:5) at Object.exports.migrateTeamProviderInfo (C:\Users\sinap\scoop\persist\nodejs\bin\node_modules@aws-amplify\cli\src\utils\team-provider-migrate.ts:26:7) at Object.run (C:\Users\sinap\scoop\persist\nodejs\bin\node_modules@aws-amplify\cli\src\index.ts:82:11)

I have noticed alsa that in cognito it is removing information from hostedUIProviderCreds

#index e17e1e5..5a40678 100644 #--- a/amplify/team-provider-info.json #+++ b/amplify/team-provider-info.json #@@ -13,10 +13,9 @@

},

"categories": {

"auth": {

#- "cognito937499ef": { #- "hostedUIProviderCreds": "[{"ProviderName":"Facebook","client_id":"XXXXXX","client_secret":"XXXXXX"},#{"ProviderName":"Google","client_id":"XXXX-XXX.apps.googleusercontent.com","client_secret":"XXXX"}]" #- }, #- "userPoolGroups": {} #+ "cognito937499ef": {}, #+ "userPoolGroups": {}, #+ "cognito7904e5ed": {}

},

erodrig avatar Nov 24 '20 05:11 erodrig

Hello guys,

Encountering the same error in my project.

Parameters: [hostedUIProviderCreds] must have values. Encountered the problem after the CLI update. Is this related to the update?

Also tried creating a new project but encountered the same error when creating a REST API.


BTW, it says "move secrets from team-provider-info.json to deployment-secrets.json" but where is the deployment-secrets.json located? Maybe, the CLI failed to create the file...

wcomicho avatar Nov 24 '20 10:11 wcomicho

Same here. I downgraded Amplify CLI to 4.29.0 and keeps happening, so I'm not sure it's related to the latest update.

asungomez avatar Nov 24 '20 10:11 asungomez

Same here. I downgraded Amplify CLI to 4.29.0 and keeps happening, so I'm not sure it's related to the latest update. Do you still encounter the error after downgrade?

wcomicho avatar Nov 24 '20 10:11 wcomicho

Yes, I do.

My amplify.yml script is:

  - backend:
      phases:
        build:
          commands:
            - chmod +x amplifypush.sh
            - ./amplifypush.sh -e dev

the amplifypush.sh file:

#!/usr/bin/env bash
set -e
IFS='|'
help_output () {
    echo "usage: amplify-push <--environment|-e <name>> <--simple|-s>"
    echo "  --environment  The name of the Amplify environment to use"
    echo "  --simple  Optional simple flag auto-includes stack info from env cache"
    exit 1
}

init_env () {
    ENV=$1
    AMPLIFY=$2
    PROVIDERS=$3
    CODEGEN=$4
    AWSCONFIG=$5
    CATEGORIES=$6
    echo "# Start initializing Amplify environment: ${ENV}"
    if [[ -z ${STACKINFO} ]];
    then
        echo "# Initializing new Amplify environment: ${ENV} (amplify init)"
        amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --categories ${CATEGORIES} --yes;
        echo "# Environment ${ENV} details:"
        amplify env get --name ${ENV}
    else
        echo "STACKINFO="${STACKINFO}
        echo "# Importing Amplify environment: ${ENV} (amplify env import)"
        amplify env import --name ${ENV} --config "${STACKINFO}" --awsInfo ${AWSCONFIG} --categories ${CATEGORIES} --yes;
        echo "# Initializing existing Amplify environment: ${ENV} (amplify init)"
        amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --yes;
        echo "# Environment ${ENV} details:"
        amplify env get --name ${ENV}
    fi
    echo "# Done initializing Amplify environment: ${ENV}"
}

ENV=""
IS_SIMPLE=false
POSITIONAL=()
while [[ $# -gt 0 ]]
do
    key="$1"
    case ${key} in
        -e|--environment)
            ENV=$2
            shift
            ;;
        -r|--region)
            REGION=$2
            shift
            ;;
        -s|--simple)
            IS_SIMPLE=true
            shift
            ;;
        *)
            POSITIONAL+=("$1")
            shift
            ;;
    esac
done

set -- "${POSITIONAL[@]}"

# if no provided environment name, use default env variable, then user override
if [[ ${ENV} = "" ]];
then
    ENV=${AWS_BRANCH}
fi
if [[ ${USER_BRANCH} != "" ]];
then
    ENV=${USER_BRANCH}
fi

# Check valid environment name
if [[ -z ${ENV} || "${ENV}" =~ [^a-zA-Z0-9\-]+ ]] ; then help_output ; fi

AWSCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"

AMPLIFY="{\
\"envName\":\"${ENV}\"\
}"

PROVIDERS="{\
\"awscloudformation\":${AWSCONFIG}\
}"

CODEGEN="{\
\"generateCode\":false,\
\"generateDocs\":false\
}"

AUTHCONFIG="{\
\"googleAppIdUserPool\":\"${GOOGLE_CLIENT_ID}\",\
\"googleAppSecretUserPool\":\"${GOOGLE_CLIENT_SECRET}\"\
}"

CATEGORIES="{\
\"auth\":$AUTHCONFIG\
}"

# Handle old or new config file based on simple flag
if [[ ${IS_SIMPLE} ]];
then
    echo "# Getting Amplify CLI Cloud-Formation stack info from environment cache"
    export STACKINFO="$(envCache --get stackInfo)"
    init_env ${ENV} ${AMPLIFY} ${PROVIDERS} ${CODEGEN} ${AWSCONFIG} ${CATEGORIES}
    echo "# Store Amplify CLI Cloud-Formation stack info in environment cache"
    STACKINFO="$(amplify env get --json --name ${ENV})"
    envCache --set stackInfo ${STACKINFO}
    echo "STACKINFO="${STACKINFO}
else
    # old config file, above steps performed outside of this script
    init_env ${ENV} ${AMPLIFY} ${PROVIDERS} ${CODEGEN} ${AWSCONFIG} ${CATEGORIES}
fi

I got this code from https://github.com/aws-amplify/amplify-console/issues/206

asungomez avatar Nov 24 '20 11:11 asungomez

Hi guys,

Tried using southeast with root account. encountering the same error after doing an update.

image

wcomicho avatar Nov 24 '20 12:11 wcomicho

I think https://github.com/aws-amplify/amplify-cli/pull/5733 introduced this change, and was approved by at least one contributor to the project.

It looks like the migration code has been tested here: https://github.com/aws-amplify/amplify-cli/blob/d18f795560f0e671f63f1dcbe38931c951794619/packages/amplify-cli/src/tests/team-provider-migrate.test.ts#L143-L144

If I understand the test correctly it appears to assert that some code was called but does nothing to verify the behaviour (i.e. that a file is created on disk, that the contents of the file are correct, that a subsequent invocation of amplify push succeeds).

The description in the PR mentions a ~/,aws/amplify/deployment-secrets.json, which I'm guessing is a typo and should be ~/.aws/amplify/deployment-secrets.json? Mine contains this:

{
  "appSecrets": []
}

I've found the following type that specifies the expected format of the new JSON file:

https://github.com/aws-amplify/amplify-cli/blob/ad7b028330bcee64d5124be7f27a8494dc8e9400/packages/amplify-cli-core/src/index.ts#L59-L65

Given the severity of this issue (any affected customer will be unable to push changes to any Amplify backend) I'd like to humbly request a post-mortem on how this problem found its way to customers, and how the Amplify team plan to avoid causing this sort of disruption in future.

I hope some of the info above is helpful. If there's anything else I can do to help triage and resolve please holla. :mega:

jcf avatar Nov 24 '20 17:11 jcf

@wcomicho The file should be under~/.aws/amplify/deployment-secrets.json

ammarkarachi avatar Nov 24 '20 18:11 ammarkarachi

I am also having this issue. I upgraded to 4.35.0 and am receiving this error when trying to amplify push:

[hostedUIProviderCreds] must have values

The deployment-secrets.json file gets created but only has this in it:

{
  "appSecrets": []
}

askurat avatar Nov 24 '20 21:11 askurat

Ok, so I was able to get this to work. It seems like version 4.34.0 removed the hostedUIProviderCreds: [] in the team-provider-info.json but didn't successfully add it to deployment-secrets.json.

I updated the categories section in team-provider-info.json with:

"auth": {
   "[api_name]": {
     "hostedUIProviderCreds": "[]"
   },
   "userPoolGroups": {}
 },

The next time I ran amplify push it asked me to migrate to deployment-secrets.json and if I wanted to backup team-provider-info.json. I said yes and it successfully updated deployment-secrets.json:

{
  "appSecrets": [
    {
      "rootStackId": "[stack_id]",
      "environments": {
        "dev": {
          "auth": {
            "[api_name]": {
              "hostedUIProviderCreds": "[]"
            }
          }
        }
      }
    }
  ]
}

askurat avatar Nov 24 '20 21:11 askurat

The hostedUIProviderCreds gets managed in deployment secrets and then gets discarded after a successful push. I am curious whether there is a failure on the CLI end where this file isn't being written. @askurat did the file have the hostedUIProviderCreds before the push?

ammarkarachi avatar Nov 24 '20 22:11 ammarkarachi

@ammarkarachi I do not remember if the CLI threw an error at me or not. After I upgraded to version 4.34.0 I do remember it asking me if I wanted to backup team-provider-info.json. I recall typing yes but don't remember if it errored on me or not. I was able to push after that upgrade.

When I updated to version 4.35.0 this morning and tried to do a push, it gave me the [hostedUIProviderCreds] must have values error. I then checked my team-provider-info.json on another branch, pre-upgrade, and noticed under the categories -> auth section, I had:

"[api_name]": {
   "hostedUIProviderCreds": "[]"
 },

So I added that back into my team-provider-info.json file, re-ran amplify push, and the CLI then asked me to migrate to deployment-secrets.json again. After it migrated I checked the deployment-secrets.json file and the hostedUIProviderCreds were added. Upon a successful push, hostedUIProviderCreds were removed but every push since has worked.

I hope all that made sense.

I'm guessing forcing the migration again must correct something in the CLI?

askurat avatar Nov 24 '20 22:11 askurat

This is a really rough one, I though it was just me so I tweeted about it then forgot about it https://twitter.com/CodingCatDev/status/1330596528889745410

There has to be a better way of making this and the team-provider-info.json details work more easily.

Especially in regards to the auth redirects. Those need to be moved from amplify-meta.json to team-provider-info.json. We are opening a door here (all be it not a huge one) as you are allowing other domains access in your production environments if you add them to this list.

codercatdev avatar Nov 25 '20 00:11 codercatdev

Tried putting an entry in the deployment-secrets.json: { "rootStackId": "[my stack id here]", "environments": { "dev": { "auth": { "my auth input": { "hostedUIProviderCreds": "[my google config]" } } } } }

but now I am getting error message in cloudformation: The following resource(s) failed to create: [testDynamoDB]. The following resource(s) failed to update: [authtest2020].

wcomicho avatar Nov 25 '20 01:11 wcomicho

@askurat's fix worked for me too. I restored my team-provider-info.json from a btrfs snapshot, ran amplify push, and was prompted to migrate. Answering yes to the prompt resulted in my ~/.aws/amplify/deployment-secrets.json being updated to contain my hostedUIProviderCreds.

jcf avatar Nov 25 '20 10:11 jcf

I'm having the same problem as others here with Amplify CLI v4.35.0.

When I try to run amplify push, it asked me to back up to deployment-secrets.json (selecting "no" by the way, cancels the push process, so you must backup in order to continue... this (a) really needs a rephrased question for clarity, and (b) needs documentation as I searched everywhere for deployment-secrets in my project (thought it would be a file to .gitignore or something), only to find out in this thread that it's in my local AWS config...).

So I selected "yes", and it removed the hostedUIProviderCreds object in the team-provider-info.json. It then threw an error UPDATE_FAILED auth<AUTH_NAME> AWS::CloudFormation::Stack Tue Nov 24 2020 21:14:46 GMT-0500 (Eastern Standard Time) Parameters: [hostedUIProviderCreds] do not exist in the template

And since I didn't know what was going on, I tried a bunch of different things to no avail, including running amplify update auth to re-add the FB / Google IDs in. This actually added the following into my team-provider-info.json:

"categories": { "auth": { "<AUTH_NAME_": { "facebookAppId": "<FB_ID>", "googleClientId": "<GOOGLE_ID>" } },

After checking this thread, I have the hostedUIProviderCreds in deployment-secrets.json, but I'm still encountering the same [hostedUIProviderCreds] do not exist in the template error.

If I remove the facebookAppId and googleClientId entires, I get a new error: UPDATE_FAILED authtraintheoryweb843b1bda AWS::CloudFormation::Stack Wed Nov 25 2020 11:28:45 GMT-0500 (Eastern Standard Time) Parameters: [facebookAppId, googleClientId] do not exist in the template

I tried @askurat 's fix as well, but it still gives me the same [hostedUIProviderCreds] do not exist in the template error.

So I'm a bit stuck. I'll try a few more things and then I'll likely have to revert back to an old CLI version for the time-being.

ngnathan avatar Nov 25 '20 16:11 ngnathan

@ngnathan US-EAST-1 Region is having a ton of issues at the moment. This may be causing some of your problems: AWS Status

askurat avatar Nov 25 '20 16:11 askurat

I thought i was going crazy and kept checking the status. I really dig the new personal health dashboard. image

codercatdev avatar Nov 25 '20 16:11 codercatdev

@ngnathan US-EAST-1 Region is having a ton of issues at the moment. This may be causing some of your problems: AWS Status

Yeah I just saw this as well... I just tried (in a separate env) removing FB/Google (so that I can try adding it again). And I think the us-east-1 issues are causing my CLI to be stuck on updating the IdentityPool during my amplify push lol.

Anyway, I'm not sure how recent this outage is, but I was dealing with the same problems all of yesterday too.

ngnathan avatar Nov 25 '20 17:11 ngnathan