package main
import (
"fmt"
"os"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam"
"github.com/IBM/ibm-cos-sdk-go/aws/session"
"github.com/IBM/ibm-cos-sdk-go/service/s3"
)
const (
serviceInstanceID = "crn-of-target-cos-instance"
authEndpoint = "https://iam.cloud.ibm.com/identity/token"
serviceEndpoint = "cos-endpoint"
trustedProfileName = "name-of-trusted-profile"
accountId = "account-id-that-owns-trusted-profile"
serviceIDApiKey = "api-key-of-service-id"
)
func TestTrustedProfile
func main() {
sess := session.Must(session.NewSession())
conf := aws.NewConfig().
WithRegion("us-south").
WithEndpoint(serviceEndpoint). WithCredentials(ibmiam.NewTrustedProfileCredentialsServiceIDWithTrustedProfileName(aws.NewConfig(), authEndpoint, trustedProfileName, accountId, serviceIDApiKey, serviceInstanceID)).
WithS3ForcePathStyle(true)
client := s3.New(sess, conf)
lbInput := s3.ListBucketsInput{}
buckets, err := client.ListBuckets(&lbInput)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(buckets)
fmt.Println("Successfully completes (^ ~ ^)")
}
}
Once the client is created, it can be used to perform operations such as:
After setting up the client, you can perform S3 operations using the Go code examples provided here.
By following these steps the Finance team now has a secure access to the monthly sales report. Using the same steps the access can be provided to the Audit and operations team as well.
Why Use Trusted Profiles + Service IDs for Cross-Account Access
Using Trusted Profiles with Service IDs provides several benefits:
Credentials do not need to be shared across accounts.
-
Credential Management Overhead
API keys need to be created, rotated, revoked, and audited, which increases operational complexity.
Access can be revoked instantly by:
-
Fine-Grained Access Control
Each Service ID can be granted specific roles and permissions.
Trusted Profiles improve scalability by centralizing access control. Instead of configuring permissions separately for every service or account, multiple Service IDs can be attached to the same Trusted Profile and inherit its permissions, making it easier to manage access as systems grow.
Cross-account access is a common requirement in modern cloud architectures, especially in organizations that separate workloads across multiple accounts for security and governance reasons.
By combining Service IDs with Trusted Profiles, IBM Cloud provides a secure and scalable way to enable this access without sharing credentials or expanding account membership.
This approach enables secure, flexible, and maintainable cross-account authentication, making it an ideal solution for architectures such as hub-and-spoke environments, multi-team deployments, and shared infrastructure platforms. If you are building applications that interact with IBM Cloud Object Storage across multiple accounts, Trusted Profiles provide a clean and secure way to manage that access.