Documentation
¶
Overview ¶
Package cloudsec provides a client for interacting with the Cortex CloudSec API for rule and policy management.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) APIKeyID() int
- func (c *Client) APIKeyType() string
- func (c *Client) APIURL() string
- func (c *Client) CrashStackDir() string
- func (c *Client) Create(ctx context.Context, input types.CreateRuleRequest) (types.RuleResponse, error)
- func (c *Client) CreatePolicy(ctx context.Context, input types.PolicyCreateRequest) (types.PolicyResponse, error)
- func (c *Client) Delete(ctx context.Context, id string) error
- func (c *Client) DeletePolicy(ctx context.Context, id string) error
- func (c *Client) Get(ctx context.Context, id string) (types.RuleResponse, error)
- func (c *Client) GetPolicy(ctx context.Context, id string) (types.PolicyResponse, error)
- func (Client) IsCortexClient()
- func (c *Client) LogLevel() string
- func (c *Client) Logger() log.Logger
- func (c *Client) MaxRetries() int
- func (c *Client) RetryMaxDelay() time.Duration
- func (c *Client) Search(ctx context.Context, input types.SearchRulesRequest) (types.SearchRulesResponse, error)
- func (c *Client) SearchPolicies(ctx context.Context, input types.SearchPoliciesRequest) (types.SearchPoliciesResponse, error)
- func (c *Client) SkipLoggingTransport() bool
- func (c *Client) SkipSSLVerify() bool
- func (c *Client) Timeout() time.Duration
- func (c *Client) Update(ctx context.Context, id string, input types.UpdateRuleRequest) (types.RuleResponse, error)
- func (c *Client) UpdatePolicy(ctx context.Context, input types.PolicyUpdateRequest) (types.PolicyResponse, error)
- func (c *Client) ValidateAPIKey(ctx context.Context) (bool, error)
- type Option
Constants ¶
const ( // Rule Management Endpoints CreateRuleEndpoint = "public_api/v1/rule" GetRuleEndpoint = "public_api/v1/rule" SearchRulesEndpoint = "public_api/v1/rule/search" UpdateRuleEndpoint = "public_api/v1/rule" DeleteRuleEndpoint = "public_api/v1/rule" // Policy Management Endpoints CreatePolicyEndpoint = "public_api/v1/policy" GetPolicyEndpoint = "public_api/v1/policy" SearchPoliciesEndpoint = "public_api/v1/policy/search" UpdatePolicyEndpoint = "public_api/v1/policy" DeletePolicyEndpoint = "public_api/v1/policy" )
API endpoint path specification.
Variables ¶
var ( // WithCortexAPIURL is an option to set the Cortex API URL. WithCortexAPIURL = config.WithCortexAPIURL // WithCortexAPIKey is an option to set the Cortex API key. WithCortexAPIKey = config.WithCortexAPIKey // WithCortexAPIKeyID is an option to set the Cortex API key ID. WithCortexAPIKeyID = config.WithCortexAPIKeyID // WithCortexAPIKeyType is an option to set the Cortex API key type. WithCortexAPIKeyType = config.WithCortexAPIKeyType // WithCortexAPIPort is an option to set the Cortex API port. WithHeaders = config.WithHeaders // WithAgent is an option to set the user agent. WithAgent = config.WithAgent // WithSkipSSLVerify is an option to skip TLS certificate verification. WithSkipSSLVerify = config.WithSkipSSLVerify // WithTransport is an option to set the HTTP transport. WithTransport = config.WithTransport // WithTimeout is an option to set the HTTP timeout. WithTimeout = config.WithTimeout // WithMaxRetries is an option to set the maximum number of retries. WithMaxRetries = config.WithMaxRetries // WithRetryMaxDelay is an option to set the maximum retry delay. WithRetryMaxDelay = config.WithRetryMaxDelay // WithCrashStackDir is an option to set the crash stack directory. WithCrashStackDir = config.WithCrashStackDir // WithLogLevel is an option to set the log level. WithLogLevel = config.WithLogLevel // WithLogger is an option to set the logger. WithLogger = config.WithLogger // WithSkipLoggingTransport is an option to skip logging transport. WithSkipLoggingTransport = config.WithSkipLoggingTransport )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client for the namespace.
func NewClientFromFile ¶
NewClientFromFile creates a new client from a configuration file.
func (*Client) APIKeyType ¶
APIKeyType returns the Cortex API key type.
func (*Client) CrashStackDir ¶
CrashStackDir returns the crash stack directory.
func (*Client) Create ¶
func (c *Client) Create(ctx context.Context, input types.CreateRuleRequest) (types.RuleResponse, error)
Create creates a new detection rule.
This operation creates a new CSPM detection rule with the provided configuration. The rule must have a unique name, and all required fields must be provided.
Required fields:
- Name: Unique rule name (max 255 chars)
- Class: Must be 'config' for CSPM rules
- AssetTypes: Array with exactly one asset type identifier
- Severity: One of: low, medium, high, critical, informational
- Query: XQL query definition
Example:
rule, err := client.Create(ctx, types.CreateRuleRequest{
Name: "AWS S3 Bucket with Public Access",
Class: "config",
AssetTypes: []string{"aws-s3-bucket"},
Severity: "high",
Query: types.QueryRequest{
XQL: "config from cloud.resource where cloud.type = 'aws' AND api.name = 'aws-s3api-get-bucket-acl'",
},
})
func (*Client) CreatePolicy ¶
func (c *Client) CreatePolicy(ctx context.Context, input types.PolicyCreateRequest) (types.PolicyResponse, error)
CreatePolicy creates a new policy.
This operation creates a new CloudSec policy with the provided configuration. The policy must have a unique name, and all required fields must be provided.
Required fields:
- Name: Unique policy name
- RuleMatchingType: One of: ALL_RULES, RULES, RULE_FILTER
- AssetMatchingType: One of: ALL_ASSETS, ASSET_GROUPS, CLOUD_ACCOUNTS
Conditional requirements:
- If RuleMatchingType is RULE_FILTER: AssociatedRuleFilter is required
- If RuleMatchingType is RULES: AssociatedRuleIDs is required
- If AssetMatchingType is ASSET_GROUPS: AssociatedAssetGroupIDs is required
- If AssetMatchingType is CLOUD_ACCOUNTS: AssociatedCloudAccountIDs is required
Example:
policy, err := client.CreatePolicy(ctx, types.PolicyCreateRequest{
Name: "My Security Policy",
Description: "Policy for critical security rules",
RuleMatchingType: "RULES",
AssociatedRuleIDs: []string{"rule-id-1", "rule-id-2"},
AssetMatchingType: "ALL_ASSETS",
})
func (*Client) Delete ¶
Delete removes a detection rule by its ID.
This operation permanently deletes the specified rule. System default rules cannot be deleted.
Example:
err := client.Delete(ctx, "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
func (*Client) DeletePolicy ¶
DeletePolicy removes a policy by its ID.
This operation permanently deletes the specified policy. System default policies cannot be deleted.
Example:
err := client.DeletePolicy(ctx, "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
func (*Client) Get ¶
Get retrieves the details of a detection rule by its ID.
Example:
rule, err := client.Get(ctx, "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
func (*Client) GetPolicy ¶
GetPolicy retrieves the details of a policy by its ID.
Example:
policy, err := client.GetPolicy(ctx, "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
func (Client) IsCortexClient ¶
func (Client) IsCortexClient()
Marker method for CortexClient interface compliance.
func (*Client) MaxRetries ¶
MaxRetries returns the maximum number of retries.
func (*Client) RetryMaxDelay ¶
RetryMaxDelay returns the maximum retry delay.
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, input types.SearchRulesRequest) (types.SearchRulesResponse, error)
Search retrieves detection rules that match the provided filter criteria.
This operation supports complex filtering with AND/OR logic, pagination, and sorting. If no filter is provided, all rules will be returned (subject to pagination limits).
Example with filter:
resp, err := client.Search(ctx, types.SearchRulesRequest{
Filter: &types.FilterCriteria{
OR: []types.FilterCriteria{
{
SearchField: "id",
SearchType: "EQ",
SearchValue: "4f900112-eb70-490e-a867-63a31769a786",
},
{
SearchField: "severity",
SearchType: "EQ",
SearchValue: "critical",
},
},
},
SearchFrom: 0,
SearchTo: 50,
Sort: []types.SortCriteria{
{Field: "name", Order: "ASC"},
},
})
func (*Client) SearchPolicies ¶
func (c *Client) SearchPolicies(ctx context.Context, input types.SearchPoliciesRequest) (types.SearchPoliciesResponse, error)
SearchPolicies retrieves policies that match the provided filter criteria.
This operation supports complex filtering with AND/OR logic, pagination, and sorting. If no filter is provided, all policies will be returned (subject to pagination limits).
Example with filter:
resp, err := client.SearchPolicies(ctx, types.SearchPoliciesRequest{
Filter: &types.FilterCriteria{
AND: []types.FilterCriteria{
{
SearchField: "name",
SearchType: "CONTAINS",
SearchValue: "Security",
},
{
SearchField: "enabled",
SearchType: "EQ",
SearchValue: true,
},
},
},
SearchFrom: 0,
SearchTo: 50,
Sort: []types.SortCriteria{
{Field: "name", Order: "ASC"},
},
})
func (*Client) SkipLoggingTransport ¶
SkipLoggingTransport returns whether to skip logging transport.
func (*Client) SkipSSLVerify ¶
SkipSSLVerify returns whether to skip TLS certificate verification.
func (*Client) Update ¶
func (c *Client) Update(ctx context.Context, id string, input types.UpdateRuleRequest) (types.RuleResponse, error)
Update modifies an existing detection rule.
All fields in the UpdateRuleRequest are optional, allowing for partial updates. Only the fields that are provided will be updated.
For system default rules, only certain fields (like labels) can be modified. For custom rules, all fields can be modified.
Example:
rule, err := client.Update(ctx, "a1b2c3d4-e5f6-7890-abcd-ef1234567890", types.UpdateRuleRequest{
Severity: "critical",
Labels: []string{"Updated", "Critical"},
})
func (*Client) UpdatePolicy ¶
func (c *Client) UpdatePolicy(ctx context.Context, input types.PolicyUpdateRequest) (types.PolicyResponse, error)
UpdatePolicy modifies an existing policy.
All fields in the PolicyUpdateRequest are optional, allowing for partial updates. Only the fields that are provided will be updated. The ID field must be set to identify which policy to update.
For system default policies, only certain fields (like labels) can be modified. For custom policies, all fields can be modified.
Example:
policy, err := client.UpdatePolicy(ctx, types.PolicyUpdateRequest{
ID: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
Description: "Updated policy description",
Labels: []string{"Updated", "Production"},
})