cloudsec

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cloudsec provides a client for interacting with the Cortex CloudSec API for rule and policy management.

Index

Constants

View Source
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

View Source
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 NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient returns a new client for this namespace.

func NewClientFromFile

func NewClientFromFile(filepath string) (*Client, error)

NewClientFromFile creates a new client from a configuration file.

func (*Client) APIKeyID

func (c *Client) APIKeyID() int

APIKeyID returns the Cortex API key ID.

func (*Client) APIKeyType

func (c *Client) APIKeyType() string

APIKeyType returns the Cortex API key type.

func (*Client) APIURL

func (c *Client) APIURL() string

APIURL returns the API URL for the Cortex.

func (*Client) CrashStackDir

func (c *Client) CrashStackDir() string

CrashStackDir returns the crash stack directory.

func (*Client) Create

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

func (c *Client) Delete(ctx context.Context, id string) error

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

func (c *Client) DeletePolicy(ctx context.Context, id string) error

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

func (c *Client) Get(ctx context.Context, id string) (types.RuleResponse, error)

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

func (c *Client) GetPolicy(ctx context.Context, id string) (types.PolicyResponse, error)

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) LogLevel

func (c *Client) LogLevel() string

LogLevel returns the log level.

func (*Client) Logger

func (c *Client) Logger() log.Logger

Logger returns the logger.

func (*Client) MaxRetries

func (c *Client) MaxRetries() int

MaxRetries returns the maximum number of retries.

func (*Client) RetryMaxDelay

func (c *Client) RetryMaxDelay() time.Duration

RetryMaxDelay returns the maximum retry delay.

func (*Client) Search

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

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

func (c *Client) SkipLoggingTransport() bool

SkipLoggingTransport returns whether to skip logging transport.

func (*Client) SkipSSLVerify

func (c *Client) SkipSSLVerify() bool

SkipSSLVerify returns whether to skip TLS certificate verification.

func (*Client) Timeout

func (c *Client) Timeout() time.Duration

Timeout returns the HTTP timeout.

func (*Client) Update

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"},
})

func (*Client) ValidateAPIKey

func (c *Client) ValidateAPIKey(ctx context.Context) (bool, error)

ValidateAPIKey validates the configured API Key against the target Cortex tenant.

type Option

type Option = config.Option

Option is a functional option for configuring the client.

Jump to

Keyboard shortcuts

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