|
| 1 | +package resources |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/aws/aws-sdk-go/aws" |
| 8 | + "github.com/aws/aws-sdk-go/aws/session" |
| 9 | + "github.com/aws/aws-sdk-go/service/signer" |
| 10 | + "github.com/rebuy-de/aws-nuke/v2/pkg/types" |
| 11 | +) |
| 12 | + |
| 13 | +type SignerSigningJob struct { |
| 14 | + svc *signer.Signer |
| 15 | + jobId *string |
| 16 | + reason string |
| 17 | + isRevoked *bool |
| 18 | + createdAt time.Time |
| 19 | + profileName *string |
| 20 | + profileVersion *string |
| 21 | + platformId *string |
| 22 | + platformDisplayName *string |
| 23 | + jobOwner *string |
| 24 | + jobInvoker *string |
| 25 | +} |
| 26 | + |
| 27 | +func init() { |
| 28 | + register("SignerSigningJob", ListSignerSigningJobs) |
| 29 | +} |
| 30 | + |
| 31 | +func ListSignerSigningJobs(sess *session.Session) ([]Resource, error) { |
| 32 | + svc := signer.New(sess) |
| 33 | + resources := []Resource{} |
| 34 | + const reason string = "Revoked by AWS Nuke" |
| 35 | + |
| 36 | + listJobsInput := &signer.ListSigningJobsInput{} |
| 37 | + |
| 38 | + err := svc.ListSigningJobsPages(listJobsInput, func(page *signer.ListSigningJobsOutput, lastPage bool) bool { |
| 39 | + for _, job := range page.Jobs { |
| 40 | + resources = append(resources, &SignerSigningJob{ |
| 41 | + svc: svc, |
| 42 | + jobId: job.JobId, |
| 43 | + reason: reason, |
| 44 | + isRevoked: job.IsRevoked, |
| 45 | + createdAt: *job.CreatedAt, |
| 46 | + profileName: job.ProfileName, |
| 47 | + profileVersion: job.ProfileVersion, |
| 48 | + platformId: job.PlatformId, |
| 49 | + platformDisplayName: job.PlatformDisplayName, |
| 50 | + jobOwner: job.JobOwner, |
| 51 | + jobInvoker: job.JobInvoker, |
| 52 | + }) |
| 53 | + } |
| 54 | + return true // continue iterating over pages |
| 55 | + }) |
| 56 | + if err != nil { |
| 57 | + return nil, err |
| 58 | + } |
| 59 | + return resources, nil |
| 60 | +} |
| 61 | + |
| 62 | +func (j *SignerSigningJob) Filter() error { |
| 63 | + // Consider all non-revoked jobs |
| 64 | + if *j.isRevoked { |
| 65 | + return fmt.Errorf("job already revoked") |
| 66 | + } |
| 67 | + return nil |
| 68 | +} |
| 69 | + |
| 70 | +func (j *SignerSigningJob) Remove() error { |
| 71 | + // Signing jobs are viewable by the ListSigningJobs operation for two years after they are performed [1] |
| 72 | + // As a precaution we are updating Signing jobs statuses to revoked. This indicates that the signature is no longer valid. |
| 73 | + // [1] https://awscli.amazonaws.com/v2/documentation/api/latest/reference/signer/start-signing-job.html |
| 74 | + revokeInput := &signer.RevokeSignatureInput{ |
| 75 | + JobId: j.jobId, |
| 76 | + Reason: aws.String(j.reason), |
| 77 | + } |
| 78 | + _, err := j.svc.RevokeSignature(revokeInput) |
| 79 | + return err |
| 80 | +} |
| 81 | + |
| 82 | +func (j *SignerSigningJob) Properties() types.Properties { |
| 83 | + properties := types.NewProperties() |
| 84 | + properties.Set("JobId", j.jobId) |
| 85 | + properties.Set("CreatedAt", j.createdAt.Format(time.RFC3339)) |
| 86 | + properties.Set("ProfileName", j.profileName) |
| 87 | + properties.Set("ProfileVersion", j.profileVersion) |
| 88 | + properties.Set("PlatformId", j.platformId) |
| 89 | + properties.Set("PlatformDisplayName", j.platformDisplayName) |
| 90 | + properties.Set("JobOwner", j.jobOwner) |
| 91 | + properties.Set("JobInvoker", j.jobInvoker) |
| 92 | + return properties |
| 93 | +} |
0 commit comments