Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cyberark/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ func NewDatauploadClient(ctx context.Context, httpClient *http.Client, serviceMa
return nil, err
}

return dataupload.New(httpClient, discoveryAPI, identityClient.AuthenticateRequest), nil
return dataupload.New(httpClient, discoveryAPI, cfg.Subdomain, cfg.Username, identityClient.AuthenticateRequest), nil
}
36 changes: 26 additions & 10 deletions internal/cyberark/dataupload/dataupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ type CyberArkClient struct {
baseURL string
httpClient *http.Client

subdomain string
username string

authenticateRequest func(req *http.Request) error
}

func New(httpClient *http.Client, baseURL string, authenticateRequest func(req *http.Request) error) *CyberArkClient {
// TODO: should probably take a cyberark Identity client directly and query subdomain + username from that
func New(httpClient *http.Client, baseURL string, subdomain string, username string, authenticateRequest func(req *http.Request) error) *CyberArkClient {
return &CyberArkClient{
baseURL: baseURL,
httpClient: httpClient,
baseURL: baseURL,
httpClient: httpClient,

subdomain: subdomain,
username: username,

authenticateRequest: authenticateRequest,
}
}
Expand Down Expand Up @@ -102,13 +110,6 @@ type Snapshot struct {
// has been received intact.
// Read [Checking object integrity for data uploads in Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity-upload.html),
// to learn more.
//
// TODO(wallrj): There is a bug in the AWS backend:
// [S3 Presigned PutObjectCommand URLs ignore Sha256 Hash when uploading](https://github.com/aws/aws-sdk/issues/480)
// ...which means that the `x-amz-checksum-sha256` request header is optional.
// If you omit that header, it is possible to PUT any data.
// There is a work around listed in that issue which we have shared with the
// CyberArk API team.
func (c *CyberArkClient) PutSnapshot(ctx context.Context, snapshot Snapshot) error {
if snapshot.ClusterID == "" {
return fmt.Errorf("programmer mistake: the snapshot cluster ID cannot be left empty")
Expand All @@ -133,6 +134,21 @@ func (c *CyberArkClient) PutSnapshot(ctx context.Context, snapshot Snapshot) err
return err
}
req.Header.Set("X-Amz-Checksum-Sha256", checksumBase64)
req.Header.Set("X-Amz-Server-Side-Encryption", "AES256")

q := url.Values{}

q.Add("agent_version", snapshot.AgentVersion)
q.Add("tenant_id", "8f08a102-58ca-49cd-960e-debc5e0d3cd4") // TODO: this is just for testing, must fix
q.Add("upload_type", "k8s_snapshot")
q.Add("uploader_id", snapshot.ClusterID)
q.Add("username", c.username)
q.Add("vendor", "k8s")

req.Header.Set("X-Amz-Tagging", q.Encode())

fmt.Println("tags", q.Encode())

version.SetUserAgent(req)

res, err := c.httpClient.Do(req)
Expand Down
Loading