2016-09-26 9 views
1

Python IAM API用に、Container Engineでアプリケーションのデフォルトの資格情報を使用しようとしています。しかし、認証スコープが不十分であることを指摘する次のエラーが発生しています。私のプロジェクトではIAM APIが有効になっており、コードはローカルで動作します。だから、私は何が欠けているのか分からない。アプリケーションデフォルトの資格情報がGoogle Container Engineで動作しない

は私のエラーメッセージ:

22:26:16.000 
ERROR:root:<HttpError 403 when requesting https://iam.googleapis.com/v1/projects/henry-dev/serviceAccounts/[email protected]/keys?alt=json returned "Request had insufficient authentication scopes."> 
{ 
metadata: {…} 
textPayload: "ERROR:root:<HttpError 403 when requesting https://iam.googleapis.com/v1/projects/henry-dev/serviceAccounts/[email protected]/keys?alt=json returned "Request had insufficient authentication scopes."> 
" 
insertId: "116wpgtg3n4zndx" 
log: "simplekubeserver" 
} 

22:26:16.000 
HttpError: <HttpError 403 when requesting https://iam.googleapis.com/v1/projects/henry-dev/serviceAccounts/[email protected]/keys?alt=json returned "Request had insufficient authentication scopes."> 
{ 
metadata: {…} 
textPayload: "HttpError: <HttpError 403 when requesting https://iam.googleapis.com/v1/projects/henry-dev/serviceAccounts/[email protected]/keys?alt=json returned "Request had insufficient authentication scopes."> 
" 
insertId: "116wpgtg3n4znej" 
log: "simplekubeserver" 
} 

マイコード、GKE上でローカルにではなく、作品:私は、トラブルシューティングするためにやった

from oauth2client.client import GoogleCredentials 

def _iam_service(): 
    credentials = GoogleCredentials.get_application_default() 
    return discovery.build(serviceName='iam', 
         version='v1', 
         credentials=credentials) 

def list_keys(project_id, service_account_id): 
    full_name = 'projects/{0}/serviceAccounts/{1}'.format(project_id, service_account_id) 
    keys = _iam_service().projects().serviceAccounts().keys() 
    request = keys.list(name=full_name) 
    return request.execute() 

ことの一つは、使用されているサービスのアカウントを取得することです。

print credentials.service_account_email 

ローカルでは、これは私が使用している正しいサービスアカウントを示しています。 GKEのに対し、私はNoneを取得しないが、source code[email protected]

のようなものを期待し、私は以下を参照してください。

_get_application_default_credential_GCE()   
_get_application_default_credential_GAE() 

しかしGKEを明示的に何もありません。だから、私はGCEのものが使われていると仮定しています。

This docは、これがContainer Engineで動作するはずであると述べています。

Application Default Credentials are best suited for cases 
when the call needs to have the same identity and authorization level 
for the application independent of the user. This is the recommended 
approach to authorize calls to Google Cloud Platform APIs, particularly 
when you're building an application that is deployed to Google App 
Engine, **Google Container Engine**, or Google Compute Engine virtual 
machines. 

答えて

1

IAM Service Accounts APIhttps://www.googleapis.com/auth/iam又はhttps://www.googleapis.com/auth/cloud-platform範囲のいずれかを必要とします。 GKEクラスタのノード上のスコープは、クラスタ作成時(またはノードプール作成時)に定義されます。 Cloud Consoleまたはgcloudを使用してクラスタを作成した場合、デフォルトのスコープにはこれらのスコープは含まれません。クラウドコンソールで

、あなたがのgcloudを使用している場合は、指定することができ

を「有効」に「詳細」リンクと設定「クラウドプラットフォーム」をクリックすることでnew clusterにクラウド・プラットフォームの範囲を追加することができます--scopesフラグをgcloud container clusters createまたはgcloud container node-pools create

+0

に転送して、スコープを設定してください。クラウドプラットフォームスコープを有効にして新しいクラスタを作成していただきありがとうございます。スコープを変更して新しいクラスタを作成する必要がなければ、もっと素晴らしいことになります。 –

+0

実行中のクラスタのスコープを変更するには、新しいノードプールを作成し(必要なスコープで)、古いノードプールを削除します。しかし、あなたはすでにそれを過ぎているように見えます:)。うれしいことはあなたのために働いた。 –

関連する問題