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:
- 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.
- Every SDK request goes through the injected core.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
- Variables
- func NewCapability(deps core.Deps) (core.Capability, error)
- func ValidProvider(p string) bool
- type AccessKey
- type AssetPage
- type AssetRequest
- type Bucket
- type CommandRequest
- type CommandResult
- type Credentials
- type Error
- type IAMPage
- type IAMPolicy
- type IAMRequest
- type IAMUser
- type Identity
- type Instance
- type Kit
- type Object
- type Provider
- type Reason
- type StoragePage
- type StorageRequest
Constants ¶
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.
const ( AssetCompute = "compute" // ECS / CVM / EC2 AssetDatabase = "database" // RDS / CDB )
Asset kinds for cloud_asset_list.
Variables ¶
var Providers = []string{ProviderAliyun, ProviderTencent, ProviderAWS, ProviderHuawei}
Providers lists the supported vendors, for the manifest and for validation.
Functions ¶
func NewCapability ¶
func NewCapability(deps core.Deps) (core.Capability, error)
NewCapability is the registry constructor: it satisfies core.Spec.New.
func ValidProvider ¶
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 AssetRequest ¶
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 ¶
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 ¶
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.
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 ¶
New builds the kit. A host wires core.Deps.HTTP; without it the tools report unavailable rather than dialing a vendor directly.
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" )