cloudkit

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cloudkit is the cloud-asset capability: it uses a caller-supplied AK/SK to read the account's identity, instances, IAM surface and object storage, and to run a command through the vendor's cloud assistant.

Two rules shape this package:

  1. Signing is the vendor SDK's job. Each provider file wires an official Go SDK (alibabacloud-go, tencentcloud-sdk-go, aws-sdk-go-v2, huaweicloud-sdk-go-v3) and lets the SDK sign. Nothing here hand-rolls a signature, so a vendor changing its scheme is a dependency bump, not a silent breakage.
  2. Every SDK request goes through the injected capkit.HTTPDoer, so the host's scope check, rate limit and audit still apply. A host must allow the vendor endpoints it wants reachable, otherwise the tool is blocked like any other out-of-scope call.

All tools are read-only except cloud_run_command, which is risk=high and therefore requires the runtime's approval gate. Nothing here deletes or mutates a cloud resource: no instance termination, no object deletion, no IAM policy write, no AccessKey creation.

Index

Constants

View Source
const (
	ProviderAliyun  = "aliyun"
	ProviderTencent = "tencent"
	ProviderAWS     = "aws"
	ProviderHuawei  = "huawei"
)

Providers supported by this kit. huawei is present because the SDK injects cleanly; the tool surface is identical across providers.

View Source
const (
	AssetCompute  = "compute"  // ECS / CVM / EC2
	AssetDatabase = "database" // RDS / CDB
)

Asset kinds for cloud_asset_list.

Variables

Providers lists the supported vendors, for the manifest and for validation.

Functions

func NewCapability

func NewCapability(deps capkit.Deps) (capkit.Capability, error)

NewCapability is the registry constructor: it satisfies capkit.Spec.New.

func ValidProvider

func ValidProvider(p string) bool

ValidProvider reports whether p is a vendor this kit implements.

Types

type AccessKey

type AccessKey struct {
	User      string `json:"user"`
	ID        string `json:"id"`
	Status    string `json:"status,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
}

AccessKey is one access key belonging to a sub-account. It is metadata only: the secret is never returned by any vendor API.

type AssetPage

type AssetPage struct {
	Instances []Instance
	Total     int
	Cursor    string
	HasMore   bool
	// Warnings records a kind that failed while another succeeded, so the tool
	// can report StatusPartial honestly instead of dropping it.
	Warnings []string
}

type AssetRequest

type AssetRequest struct {
	Kinds    []string
	Region   string
	PageSize int
	Cursor   string
}

AssetRequest lists compute/database instances.

type Bucket

type Bucket struct {
	Name      string `json:"name"`
	Region    string `json:"region,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
}

Bucket is one object-storage bucket.

type CommandRequest

type CommandRequest struct {
	InstanceID string
	Command    string
	TimeoutSec int
	Region     string
}

CommandRequest runs one command through the vendor's cloud assistant.

type CommandResult

type CommandResult struct {
	InstanceID string `json:"instance_id"`
	CommandID  string `json:"command_id"`
	Status     string `json:"status"`
	ExitCode   int    `json:"exit_code"`
	Stdout     string `json:"stdout,omitempty"`
	Stderr     string `json:"stderr,omitempty"`
	Truncated  bool   `json:"truncated,omitempty"`
	StdoutSize int    `json:"stdout_bytes,omitempty"`
}

CommandResult is the outcome of one cloud-assistant invocation. Stdout is bounded by the caller; anything larger is stored as evidence and referenced.

type Credentials

type Credentials struct {
	AccessKey string
	SecretKey string
	Region    string
	// Endpoint optionally overrides the vendor endpoint (sovereign cloud,
	// private endpoint, or a test double's host).
	Endpoint string
}

Credentials is one AK/SK pair plus its scope. It is built from the tool input on every call and never stored: no kit state, no disk, no log line.

type Error

type Error struct {
	Reason   Reason
	Provider string
	Code     string // vendor error code, verbatim
	Message  string // vendor message, verbatim (already public to the caller)
	MaskedAK string // AK 前 4 + 后 4
}

Error is a classified vendor failure. It carries the raw vendor code for the developer and a masked AK for the agent; the secret never appears.

func (*Error) AsCapkit

func (e *Error) AsCapkit() *capkit.Error

AsCapkit renders the reason as a capkit error: a stable Code from the fixed enum, a one-line agent-readable message carrying the masked AK, a Hint that says how to fix the input, and the raw vendor code in Detail.

func (*Error) AsResult

func (e *Error) AsResult() capkit.Result

AsResult wraps the failure in a Result envelope.

func (*Error) Error

func (e *Error) Error() string

type IAMPage

type IAMPage struct {
	Users      []IAMUser
	Policies   []IAMPolicy
	AccessKeys []AccessKey
	Total      int
	Cursor     string
	HasMore    bool
	Warnings   []string
}

type IAMPolicy

type IAMPolicy struct {
	Name        string `json:"name"`
	ID          string `json:"id,omitempty"`
	Description string `json:"description,omitempty"`
	Attachments int    `json:"attachments"`
	Admin       bool   `json:"admin,omitempty"`
}

IAMPolicy is one managed policy and how widely it is attached.

type IAMRequest

type IAMRequest struct {
	Include    []string // users | policies | access_keys
	MaxResults int
	Cursor     string
}

IAMRequest lists the sub-account surface.

type IAMUser

type IAMUser struct {
	Name      string `json:"name"`
	ID        string `json:"id,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
	// AdminHint is set when a directly attached policy looks like full
	// administrative access — the privesc surface an operator cares about.
	AdminHint string `json:"admin_hint,omitempty"`
}

IAMUser is one sub-account.

type Identity

type Identity struct {
	AccountID string `json:"account_id,omitempty"`
	ARN       string `json:"arn,omitempty"`
	Type      string `json:"type,omitempty"` // root_account | ram_user | iam_user | assumed_role | federated_user | ...
	Alias     string `json:"alias,omitempty"`
}

Identity is the caller a credential belongs to, as reported by the vendor.

type Instance

type Instance struct {
	ID        string   `json:"id"`
	Name      string   `json:"name,omitempty"`
	Kind      string   `json:"kind"` // compute | database
	Status    string   `json:"status,omitempty"`
	Type      string   `json:"type,omitempty"`
	Region    string   `json:"region,omitempty"`
	Zone      string   `json:"zone,omitempty"`
	PrivateIP []string `json:"private_ips,omitempty"`
	PublicIP  []string `json:"public_ips,omitempty"`
	Engine    string   `json:"engine,omitempty"` // database engine/version
}

Instance is one compute or database asset, normalized across vendors.

type Kit

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

Kit is the cloud capability. It holds only ports: credentials arrive per call and are never retained.

func New

func New(deps capkit.Deps) *Kit

New builds the kit. A host wires capkit.Deps.HTTP; without it the tools report unavailable rather than dialing a vendor directly.

func (*Kit) Call

func (k *Kit) Call(ctx context.Context, call capkit.Call) (capkit.Result, error)

Call routes one tool invocation and stamps the envelope.

func (*Kit) Manifest

func (k *Kit) Manifest() capkit.Manifest

Manifest exposes the read-only cloud surface plus the one high-risk cloud-assistant tool.

type Object

type Object struct {
	Key          string `json:"key"`
	Size         int64  `json:"size"`
	LastModified string `json:"last_modified,omitempty"`
}

Object is one object inside a bucket. Only object metadata travels in Data; bodies never do.

type Provider

type Provider interface {
	// Name is the provider constant.
	Name() string
	// Verify performs the minimal read that proves the credential works
	// (GetCallerIdentity and its equivalents).
	Verify(ctx context.Context, creds Credentials) (Identity, error)
	// ListAssets lists compute and database instances.
	ListAssets(ctx context.Context, creds Credentials, req AssetRequest) (AssetPage, error)
	// ListIAM lists sub-accounts, policies and access-key metadata.
	ListIAM(ctx context.Context, creds Credentials, req IAMRequest) (IAMPage, error)
	// ListStorage lists buckets, or the objects of one bucket.
	ListStorage(ctx context.Context, creds Credentials, req StorageRequest) (StoragePage, error)
	// RunCommand runs one command through the vendor's cloud assistant.
	RunCommand(ctx context.Context, creds Credentials, req CommandRequest) (CommandResult, error)
}

Provider is one vendor, implemented by the per-vendor files in this package. Every method must be safe for concurrent use and must return a *Error for vendor-side failures so the kit can classify them.

type Reason

type Reason string

Reason is the normalized cloud failure, so an agent can tell "my key is wrong" from "my key lacks this permission" from "this region does not exist" without parsing vendor prose. The brief requires those to be distinguishable; vendor error codes differ per vendor, so each provider file maps its own codes into this set.

const (
	// ReasonInvalidCredential: the vendor rejected the AK/SK itself.
	ReasonInvalidCredential Reason = "invalid_credential"
	// ReasonPermissionDenied: the key is real but lacks the action's permission.
	ReasonPermissionDenied Reason = "permission_denied"
	// ReasonRegionInvalid: the region is unknown to the vendor or the endpoint.
	ReasonRegionInvalid Reason = "region_invalid"
	// ReasonInstanceNotRunning: the instance exists but is not in a state that
	// accepts a cloud-assistant command.
	ReasonInstanceNotRunning Reason = "instance_not_running"
	// ReasonNotFound: the named resource (instance, bucket) does not exist.
	ReasonNotFound Reason = "not_found"
	// ReasonThrottled: the vendor rate-limited the call.
	ReasonThrottled Reason = "throttled"
	// ReasonTimeout: the call did not finish in time.
	ReasonTimeout Reason = "timeout"
	// ReasonUnsupported: the vendor API has no equivalent for the request.
	ReasonUnsupported Reason = "unsupported"
	// ReasonUpstream: anything else the vendor returned.
	ReasonUpstream Reason = "upstream_error"
)

func (Reason) Label

func (r Reason) Label() string

Label returns the agent-facing phrase for the reason.

type StoragePage

type StoragePage struct {
	Buckets  []Bucket
	Objects  []Object
	Total    int
	Cursor   string
	HasMore  bool
	Warnings []string
}

type StorageRequest

type StorageRequest struct {
	Bucket     string
	Prefix     string
	MaxResults int
	Cursor     string
}

StorageRequest lists buckets, or the objects of one bucket.

Jump to

Keyboard shortcuts

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