Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Add SignerSigningJob module #991

Merged
merged 5 commits into from
May 24, 2023
Merged
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
93 changes: 93 additions & 0 deletions resources/signer.signingjobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package resources

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/signer"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type SignerSigningJob struct {
svc *signer.Signer
jobId *string
reason string
isRevoked *bool
createdAt time.Time
profileName *string
profileVersion *string
platformId *string
platformDisplayName *string
jobOwner *string
jobInvoker *string
}

func init() {
register("SignerSigningJob", ListSignerSigningJobs)
}

func ListSignerSigningJobs(sess *session.Session) ([]Resource, error) {
svc := signer.New(sess)
resources := []Resource{}
const reason string = "Revoked by AWS Nuke"

listJobsInput := &signer.ListSigningJobsInput{}

err := svc.ListSigningJobsPages(listJobsInput, func(page *signer.ListSigningJobsOutput, lastPage bool) bool {
for _, job := range page.Jobs {
resources = append(resources, &SignerSigningJob{
svc: svc,
jobId: job.JobId,
reason: reason,
isRevoked: job.IsRevoked,
createdAt: *job.CreatedAt,
profileName: job.ProfileName,
profileVersion: job.ProfileVersion,
platformId: job.PlatformId,
platformDisplayName: job.PlatformDisplayName,
jobOwner: job.JobOwner,
jobInvoker: job.JobInvoker,
})
}
return true // continue iterating over pages
})
if err != nil {
return nil, err
}
return resources, nil
}

func (j *SignerSigningJob) Filter() error {
// Consider all non-revoked jobs
if *j.isRevoked {
return fmt.Errorf("job already revoked")
}
return nil
}

func (j *SignerSigningJob) Remove() error {
// Signing jobs are viewable by the ListSigningJobs operation for two years after they are performed [1]
// As a precaution we are updating Signing jobs statuses to revoked. This indicates that the signature is no longer valid.
// [1] https://awscli.amazonaws.com/v2/documentation/api/latest/reference/signer/start-signing-job.html
revokeInput := &signer.RevokeSignatureInput{
JobId: j.jobId,
Reason: aws.String(j.reason),
}
_, err := j.svc.RevokeSignature(revokeInput)
return err
}

func (j *SignerSigningJob) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("JobId", j.jobId)
properties.Set("CreatedAt", j.createdAt.Format(time.RFC3339))
properties.Set("ProfileName", j.profileName)
properties.Set("ProfileVersion", j.profileVersion)
properties.Set("PlatformId", j.platformId)
properties.Set("PlatformDisplayName", j.platformDisplayName)
properties.Set("JobOwner", j.jobOwner)
properties.Set("JobInvoker", j.jobInvoker)
return properties
}