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.