alibabacloud

package module
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

README

Alibaba Cloud Authentication Plugin for IDaaS Go Core SDK

Authentication plugin for machine-to-machine access to Alibaba Cloud IDaaS EIAM. The plugin obtains an Alibaba Cloud credential from the official default credential chain and calls EIAM GenerateOauthToken.

简体中文

Requirements

  • Go 1.21 or later
  • An Alibaba Cloud credential accepted by credentials-go
  • An IDaaS EIAM application authorized for the requested scopes

Installation

go get github.com/cloud-idaas/idaas-go-core-alibabacloud-authentication-plugin

The plugin depends on the published cloud-idaas/idaas-go-core-sdk module.

Configuration

The plugin name is stable and must be configured as alibabacloudPluginCredentialProvider.

{
  "idaasInstanceId": "idaas_xxx",
  "clientId": "app_xxx",
  "issuer": "https://example.com/api/v2/iauths_system/oauth2",
  "tokenEndpoint": "https://example.com/api/v2/iauths_system/oauth2/token",
  "scope": "api.example.com|read:file api.example.com|write:file",
  "openApiEndpoint": "eiam.cn-hangzhou.aliyuncs.com",
  "authnConfiguration": {
    "identityType": "CLIENT",
    "authnMethod": "plugin",
    "pluginName": "alibabacloudPluginCredentialProvider"
  },
  "httpConfiguration": {
    "connectTimeout": 5000,
    "readTimeout": 10000
  }
}
Plugin-specific requirements
Field Required Description
idaasInstanceId Yes IDaaS EIAM instance ID
clientId Yes IDaaS application ID
scope Yes One or more audience and scope-value pairs
openApiEndpoint Yes Official Alibaba Cloud EIAM OpenAPI endpoint
identityType Yes Must be CLIENT
authnMethod Yes Must be plugin (the Go Core SDK enum value)
pluginName Yes Must be alibabacloudPluginCredentialProvider

Scope items use the audience|scopeValue form. Multiple items must use the same audience. Duplicate values are removed and values are sorted before the request is sent.

The plugin bounds the returned token lifetime by the request duration and the EIAM ExpiresAt timestamp (Unix seconds), leaving one second of safety margin for the Core SDK's cache.

For security, the default provider accepts only HTTPS endpoints matching:

  • eiam.<region>.aliyuncs.com
  • eiam-vpc.<region>.aliyuncs.com

Paths, query strings, user information, IP literals, and non-443 ports are rejected.

Usage

Import the plugin for its registration side effect:

package main

import (
    "fmt"
    "log"

    "github.com/cloud-idaas/idaas-go-core-sdk/config"
    "github.com/cloud-idaas/idaas-go-core-sdk/factory"
    _ "github.com/cloud-idaas/idaas-go-core-alibabacloud-authentication-plugin"
)

func main() {
    cfg, err := config.NewConfigReader().LoadWithPriority(
        "~/.cloud_idaas/client-config.json",
    )
    if err != nil {
        log.Fatal(err)
    }

    coreFactory := factory.GetInstance()
    if err := coreFactory.Initialize(cfg); err != nil {
        log.Fatal(err)
    }

    provider, err := coreFactory.CreateCredentialProvider()
    if err != nil {
        log.Fatal(err)
    }
    cred, err := provider.GetCredential()
    if err != nil {
        log.Fatal(err)
    }

    // Never print or log the access token.
    fmt.Printf("Credential obtained: type=%s expiresIn=%ds\n",
        cred.GetTokenType(), cred.GetExpiresIn())
}

Run the included sample:

go run ./samples/plugin_authentication.go \
  -config ~/.cloud_idaas/client-config.json

Credential security

The plugin delegates credential discovery to credentials-go. Prefer short-lived OIDC, STS, or instance-role credentials over long-lived access keys. Do not put access keys, secret keys, or access tokens in source code, configuration files, logs, issue reports, or test fixtures.

Token caching and refresh coordination are owned by the IDaaS Go Core SDK. This plugin validates the EIAM response and never logs token material.

Development

gofmt -w .
go vet ./...
go test -race -cover ./...

See CONTRIBUTING.md, SECURITY.md, and CHANGELOG.md.

License

Apache License 2.0. See LICENSE and NOTICE.

Documentation

Overview

Package alibabacloud provides an Alibaba Cloud EIAM credential-provider plugin for the IDaaS Go Core SDK.

Import the package for its side effect to register the provider:

import _ "github.com/cloud-idaas/idaas-go-core-alibabacloud-authentication-plugin"

Index

Constants

View Source
const PluginName = "alibabacloudPluginCredentialProvider"

PluginName is the registry name used in IDaaS Core SDK configuration.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlibabaCloudPlugin

type AlibabaCloudPlugin = CredentialProvider

AlibabaCloudPlugin is retained as a compatibility alias.

type CredentialProvider

type CredentialProvider struct {
	// contains filtered or unexported fields
}

CredentialProvider obtains IDaaS machine credentials through Alibaba Cloud EIAM. Token caching and refresh coordination are handled by the Core SDK.

func NewCredentialProvider

func NewCredentialProvider() *CredentialProvider

NewCredentialProvider creates a provider backed by the Alibaba Cloud default credential chain and the official EIAM SDK.

func (*CredentialProvider) GetIDaaSCredential

func (p *CredentialProvider) GetIDaaSCredential(scope string) (credential.IDaaSCredential, error)

GetIDaaSCredential obtains an OAuth2 access token from Alibaba Cloud EIAM. Scope must contain one or more "audience|scopeValue" items sharing the same audience. The method never logs credential material; the Core SDK owns token caching and refresh behavior.

func (*CredentialProvider) GetName

func (p *CredentialProvider) GetName() string

GetName returns the stable name used to select this plugin in IDaaS configuration.

Directories

Path Synopsis
Sample: PLUGIN authentication entry point.
Sample: PLUGIN authentication entry point.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL