Repository: deislabs/ratify
Pull request #804 (2023-04-29 02:20:28)

feat: ECR basic auth registry parse and add notation plugin manager
# Description

## What this PR does / why we need it:
1. This PR fixes an issue with ECR basic auth when downloading objects through the Dynamic Plugins feature. When authenticating to ECR to download a plugin, a registry would be passed to `awsEcrBasicAuthProvider.Provide` instead of the expected artifact reference, causing an out of bounds error when calling the `RegistryFromAuth` method ([reference](https://github.com/deislabs/ratify/blob/main/pkg/utils/awsauth/utils.go#L32-L43)) on L98. ECR basic auth has been updated to use `GetRegistryHostName` which works for both registry and artifact references.

2. This PR adds a plugin manager for use with the notation verifier. The `RatifyPluginManager` implements the interface expected by `notation-go` ([reference](https://github.com/notaryproject/notation-go/blob/main/plugin/manager.go#L20)), but searches for plugins in the default dynamic plugins directory (`/.ratify/plugins/`) rather than the notation default (`$XDG_CONFIG_HOME/notation/plugins`). This allows users to download notation plugins through the ratify Dynamic Plugins feature to use in verification.

## Which issue(s) this PR fixes *(optional, using `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when the PR gets merged)*:
Fixes #

## Type of change

Please delete options that are not relevant.

- [X] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Helm Chart Change (any edit/addition/update that is necessary for changes merged to the `main` branch)
- [ ] This change requires a documentation update

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also list any relevant details for your test configuration

Tested by building ratify locally and storing the image in ECR. Ratify was installed on an EKS cluster running Kubernetes 1.24.

- [X] Test ECR Auth Fix - tested by downloading a plugin from an ECR private repo.

Resource:
```
apiVersion: config.ratify.deislabs.io/v1beta1
kind: Verifier
metadata:
  name: plugin-test
spec:
  name: notation-plugin.test
  artifactTypes: application/vnd.oci.image.manifest.v1+json
  source:
    artifact: 000000000000.dkr.ecr.us-west-2.amazonaws.com/plugin-test:v1
    authProvider:
      name: awsEcrBasic
```

Logs from before fix:
```
time="2023-04-29T01:33:46Z" level=info msg="selected auth provider: awsEcrBasic"
time="2023-04-29T01:33:46Z" level=info msg="Observed a panic in reconciler: runtime error: slice bounds out of range [:-1]" controller=verifier controllerGroup=config.ratify.deislabs.io controllerKind=Verifier name=test-plugin namespace= reconcileID=7b761d21-b1af-434b-92c2-d034023c03ad verifier=test-plugin
panic: runtime error: slice bounds out of range [:-1] [recovered]
	panic: runtime error: slice bounds out of range [:-1] [recovered]
	panic: runtime error: slice bounds out of range [:-1]

goroutine 282 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
	/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.3/pkg/internal/controller/controller.go:118 +0x1f4
panic({0x1b4aba0, 0xc000184270})
	/usr/local/go/src/runtime/panic.go:884 +0x212
oras.land/oras-go/v2/internal/syncutil.(*Once).Do.func1()
	/go/pkg/mod/oras.land/oras-go/v2@v2.0.2/internal/syncutil/once.go:49 +0x65
panic({0x1b4aba0, 0xc000184270})
	/usr/local/go/src/runtime/panic.go:884 +0x212
github.com/deislabs/ratify/pkg/utils/awsauth.RegistryFromImage({0xc0005b8008, 0x2c})
	/app/pkg/utils/awsauth/utils.go:42 +0xce
github.com/deislabs/ratify/pkg/common/oras/authprovider/aws.(*awsEcrBasicAuthProvider).Provide(0xc0006280d8, {0x40db07?, 0x20?}, {0xc0005b8008, 0x2c})
	/app/pkg/common/oras/authprovider/aws/awsecrbasic.go:160 +0xfb
...
```
Logs from after fix:
```
time="2023-04-29T01:39:44Z" level=info msg="selected auth provider: awsEcrBasic"
time="2023-04-29T01:39:44Z" level=debug msg="artifact = 000000000000.dkr.ecr.us-west-2.amazonaws.com"
time="2023-04-29T01:39:44Z" level=debug msg="ecrAuthToken for 000000000000.dkr.ecr.us-west-2.amazonaws.com does not exist"
time="2023-04-29T01:39:44Z" level=debug msg="AWS ECR basic artifact=000000000000.dkr.ecr.us-west-2.amazonaws.com, registry=000000000000.dkr.ecr.us-west-2.amazonaws.com, region=us-west-2"
time="2023-04-29T01:39:44Z" level=debug msg="Resolved plugin manifest: {application/vnd.oci.image.manifest.v1+json sha256:c155f63748fd7e9946e393f2d12a24b352a88fded23f4de42a7a2d1c34b42c39 567 [] map[] [] <nil> }"
time="2023-04-29T01:39:44Z" level=debug msg="Downloading blob {000000000000.dkr.ecr.us-west-2.amazonaws.com/plugin-test:v1 map[name:awsEcrBasic]}@sha256:f79a20ed07ab0d9edb78dce11329b47b83507c5be99fa75996d85b3a1842fa4e"
time="2023-04-29T01:39:45Z" level=debug msg="writing plugin bytes to /.ratify/plugins/notation-plugin.test"
time="2023-04-29T01:39:45Z" level=debug msg="marking /.ratify/plugins/notation-plugin.test as executable"
time="2023-04-29T01:39:45Z" level=info msg="downloaded verifier plugin notation-plugin.test from 000000000000.dkr.ecr.us-west-2.amazonaws.com/plugin-test:v1 to /.ratify/plugins/notation-plugin.test"
time="2023-04-29T01:39:45Z" level=info msg="verifier 'notation-plugin.test' added to verifier map"
```
- [ ] Test Notation Plugin Manager - added unit tests to validate that the plugin manager finds files correctly and doesn't consider invalid files/directories.

# Checklist:

- [X] Does the affected code have corresponding tests?
- [ ] Are the changes documented, not just with inline documentation, but also with conceptual documentation such as an overview of a new feature, or task-based documentation like a tutorial? Consider if this change should be announced on your project blog.
- [ ] Does this introduce breaking changes that would require an announcement or bumping the major version?
- [X] Do all new files have appropriate license header?

# Post Merge Requirements
- [ ] MAINTAINERS: manually trigger the "Publish Package" workflow after merging any PR that indicates `Helm Chart Change`


microsoft-github-policy-service[bot]: 
@byronchien please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

```
@microsoft-github-policy-service agree [company="{your company}"]
```

> Options:
> - (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
>```
>@microsoft-github-policy-service agree
>```
> - (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
>```
>@microsoft-github-policy-service agree company="Microsoft"
>```

<details>
    <summary>Contributor License Agreement</summary>
    
### Contribution License Agreement
This Contribution License Agreement (**“Agreement”**) is agreed to by the party signing below (**“You”**),
and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your
contributions to Microsoft open source projects. This Agreement is effective as of the latest signature
date below.
1. **Definitions**.
**“Code”** means the computer software code, whether in human-readable or machine-executable form,
that is delivered by You to Microsoft under this Agreement.
**“Project”** means any of the projects owned or managed by Microsoft and offered under a license
approved by the Open Source Initiative (www.opensource.org).
**“Submit”** is the act of uploading, submitting, transmitting, or distributing code or other content to any
Project, including but not limited to communication on electronic mailing lists, source code control
systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
discussing and improving that Project, but excluding communication that is conspicuously marked or
otherwise designated in writing by You as “Not a Submission.”
**“Submission”** means the Code and any other copyrightable material Submitted by You, including any
associated comments and documentation.
2. **Your Submission**. You must agree to the terms of this Agreement before making a Submission to any
Project. This Agreement covers any and all Submissions that You, now or in the future (except as
described in Section 4 below), Submit to any Project.
3. **Originality of Work**. You represent that each of Your Submissions is entirely Your original work.
Should You wish to Submit materials that are not Your original work, You may Submit them separately
to the Project if You (a) retain all copyright and license information that was in the materials as You
received them, (b) in the description accompanying Your Submission, include the phrase “Submission
containing materials of a third party:” followed by the names of the third party and any licenses or other
restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
guidelines concerning Submissions.
4. **Your Employer**. References to “employer” in this Agreement include Your employer or anyone else
for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
Submission is made in the course of Your work for an employer or Your employer has intellectual
property rights in Your Submission by contract or applicable law, You must secure permission from Your
employer to make the Submission before signing this Agreement. In that case, the term “You” in this
Agreement will refer to You and the employer collectively. If You change employers in the future and
desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
and secure permission from the new employer before Submitting those Submissions.
5. **Licenses**.
  * **Copyright License**. You grant Microsoft, and those who receive the Submission directly or
indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
parties.
  * **Patent License**. You grant Microsoft, and those who receive the Submission directly or
indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
Your patent claims that are necessarily infringed by the Submission or the combination of the
Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
import or otherwise dispose of the Submission alone or with the Project.
  * **Other Rights Reserved**. Each party reserves all rights not expressly granted in this Agreement.
No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
granted by implication, exhaustion, estoppel or otherwise.
6. **Representations and Warranties**. You represent that You are legally entitled to grant the above
licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
have disclosed under Section 3). You represent that You have secured permission from Your employer to
make the Submission in cases where Your Submission is made in the course of Your work for Your
employer or Your employer has intellectual property rights in Your Submission by contract or applicable
law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
7. **Notice to Microsoft**. You agree to notify Microsoft in writing of any facts or circumstances of which
You later become aware that would make Your representations in this Agreement inaccurate in any
respect.
8. **Information about Submissions**. You agree that contributions to Projects and information about
contributions may be maintained indefinitely and disclosed publicly, including Your name and other
information that You submit with Your Submission.
9. **Governing Law/Jurisdiction**. This Agreement is governed by the laws of the State of Washington, and
the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
defenses of lack of personal jurisdiction and forum non-conveniens.
10. **Entire Agreement/Assignment**. This Agreement is the entire agreement between the parties, and
supersedes any and all prior agreements, understandings or communications, written or oral, between
the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

</details>
<!-- Policy app identification https://img.shields.io/static/v1?label=ContributorLicenseAgreement. -->
codecov[bot]: ## [Codecov](https://codecov.io/gh/deislabs/ratify/pull/804?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
Patch coverage: **`66.66`**% and project coverage change: **`+0.13`** :tada:
> Comparison is base [(`b22f919`)](https://codecov.io/gh/deislabs/ratify/commit/b22f91931cb0d2f87850839dbf400e054cc5fd6d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 52.28% compared to head [(`9ada0ec`)](https://codecov.io/gh/deislabs/ratify/pull/804?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 52.42%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #804      +/-   ##
==========================================
+ Coverage   52.28%   52.42%   +0.13%     
==========================================
  Files          61       62       +1     
  Lines        3653     3676      +23     
==========================================
+ Hits         1910     1927      +17     
- Misses       1551     1555       +4     
- Partials      192      194       +2     
```


| [Impacted Files](https://codecov.io/gh/deislabs/ratify/pull/804?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [pkg/common/oras/authprovider/aws/awsecrbasic.go](https://codecov.io/gh/deislabs/ratify/pull/804?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cGtnL2NvbW1vbi9vcmFzL2F1dGhwcm92aWRlci9hd3MvYXdzZWNyYmFzaWMuZ28=) | `15.92% <0.00%> (ø)` | |
| [pkg/verifier/notaryv2/pluginmanager.go](https://codecov.io/gh/deislabs/ratify/pull/804?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cGtnL3ZlcmlmaWVyL25vdGFyeXYyL3BsdWdpbm1hbmFnZXIuZ28=) | `73.91% <73.91%> (ø)` | |
| [pkg/verifier/notaryv2/notaryv2.go](https://codecov.io/gh/deislabs/ratify/pull/804?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cGtnL3ZlcmlmaWVyL25vdGFyeXYyL25vdGFyeXYyLmdv) | `86.04% <100.00%> (ø)` | |


</details>

[:umbrella: View full report in Codecov by Sentry](https://codecov.io/gh/deislabs/ratify/pull/804?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).

byronchien: @microsoft-github-policy-service agree company="Amazon"

Patch:
diff --git a/pkg/common/oras/authprovider/aws/awsecrbasic.go b/pkg/common/oras/authprovider/aws/awsecrbasic.go
index 7e868e9..45c60b9 100644
--- a/pkg/common/oras/authprovider/aws/awsecrbasic.go
+++ b/pkg/common/oras/authprovider/aws/awsecrbasic.go
@@ -95,14 +95,15 @@ func (d *awsEcrBasicAuthProvider) getEcrAuthToken(artifact string) (EcrAuthToken
 	}
 
 	// registry/region from image
-	registry, err := awsauth.RegistryFromImage(artifact)
+	registry, err := provider.GetRegistryHostName(artifact)
 	if err != nil {
 		return EcrAuthToken{}, fmt.Errorf("failed to get registry from image: %w", err)
 	}
 	region = awsauth.RegionFromRegistry(registry)
-	if err != nil {
-		return EcrAuthToken{}, fmt.Errorf("failed to get region from image: %w", err)
+	if region == "" {
+		return EcrAuthToken{}, fmt.Errorf("failed to get region from image")
 	}
+
 	logrus.Debugf("AWS ECR basic artifact=%s, registry=%s, region=%s", artifact, registry, region)
 	cfg.Region = region
 
@@ -157,7 +158,7 @@ func (d *awsEcrBasicAuthProvider) Provide(ctx context.Context, artifact string)
 		return provider.AuthConfig{}, fmt.Errorf("AWS IRSA basic auth provider is not properly enabled")
 	}
 
-	registry, err := awsauth.RegistryFromImage(artifact)
+	registry, err := provider.GetRegistryHostName(artifact)
 	if err != nil {
 		return provider.AuthConfig{}, errors.Wrapf(err, "could not get ECR registry from %s", artifact)
 	}
diff --git a/pkg/verifier/notaryv2/notaryv2.go b/pkg/verifier/notaryv2/notaryv2.go
index bc825c7..8f8779c 100644
--- a/pkg/verifier/notaryv2/notaryv2.go
+++ b/pkg/verifier/notaryv2/notaryv2.go
@@ -154,7 +154,7 @@ func getVerifierService(conf *NotaryV2VerifierConfig) (notation.Verifier, error)
 		certStores: conf.VerificationCertStores,
 	}
 
-	return notaryVerifier.New(&conf.TrustPolicyDoc, store, nil)
+	return notaryVerifier.New(&conf.TrustPolicyDoc, store, NewRatifyPluginManager(defaultPluginDirectory))
 }
 
 func (v *notaryV2Verifier) verifySignature(ctx context.Context, subjectRef, mediaType string, subjectDesc oci.Descriptor, refBlob []byte) (*notation.VerificationOutcome, error) {
diff --git a/pkg/verifier/notaryv2/pluginmanager.go b/pkg/verifier/notaryv2/pluginmanager.go
new file mode 100644
index 0000000..4105c1b
--- /dev/null
+++ b/pkg/verifier/notaryv2/pluginmanager.go
@@ -0,0 +1,77 @@
+/*
+Copyright The Ratify Authors.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package notaryv2
+
+import (
+	"context"
+	"io/fs"
+	"strings"
+
+	"github.com/notaryproject/notation-go/dir"
+	"github.com/notaryproject/notation-go/plugin"
+)
+
+const (
+	notationPluginPrefix   = "notation-"
+	defaultPluginDirectory = "/.ratify/plugins"
+)
+
+// Implements interface defined in https://github.com/notaryproject/notation-go/blob/main/plugin/manager.go#L20
+type RatifyPluginManager struct {
+	pluginFS dir.SysFS
+}
+
+func NewRatifyPluginManager(directory string) *RatifyPluginManager {
+	return &RatifyPluginManager{pluginFS: dir.NewSysFS(directory)}
+}
+
+// Returns a notation Plugin for the given name if present in the target directory
+func (m *RatifyPluginManager) Get(ctx context.Context, name string) (plugin.Plugin, error) {
+	path, err := m.pluginFS.SysPath(notationPluginPrefix + name)
+	if err != nil {
+		return nil, err
+	}
+
+	// validate and create plugin
+	return plugin.NewCLIPlugin(ctx, name, path)
+}
+
+// Lists available notation plugins in the target directory
+func (m *RatifyPluginManager) List(ctx context.Context) ([]string, error) {
+	var plugins []string
+	err := fs.WalkDir(m.pluginFS, ".", func(dir string, d fs.DirEntry, err error) error {
+		if err != nil {
+			return err
+		}
+
+		typ := d.Type()
+		if typ.IsDir() || !strings.HasPrefix(d.Name(), notationPluginPrefix) {
+			// Ignore directories and files that don't start with "notation-"
+			return nil
+		}
+
+		// add plugin name
+		name := strings.ReplaceAll(d.Name(), notationPluginPrefix, "")
+		plugins = append(plugins, name)
+		return fs.SkipDir
+	})
+
+	if err != nil {
+		return nil, err
+	}
+
+	return plugins, nil
+}


Test patch:
diff --git a/pkg/common/oras/authprovider/aws/awsecrbasic_test.go b/pkg/common/oras/authprovider/aws/awsecrbasic_test.go
index 5e2bfa1..e6ff94d 100644
--- a/pkg/common/oras/authprovider/aws/awsecrbasic_test.go
+++ b/pkg/common/oras/authprovider/aws/awsecrbasic_test.go
@@ -18,6 +18,7 @@ package aws
 import (
 	"context"
 	"encoding/base64"
+	"os"
 	"strings"
 	"testing"
 	"time"
@@ -29,25 +30,35 @@ import (
 const (
 	testUsername = "AWS"
 	// #nosec G101 (Ref: https://github.com/securego/gosec/issues/295)
-	testPassword = "eyJwYXlsb2FkIjoiOThPNTFqemhaUmZWVG"
-	testProxy    = "PROXY_ENDPOINT"
-	testHost     = "123456789012.dkr.ecr.us-east-2.amazonaws.com"
+	testPassword              = "eyJwYXlsb2FkIjoiOThPNTFqemhaUmZWVG"
+	testProxy                 = "PROXY_ENDPOINT"
+	testHost                  = "123456789012.dkr.ecr.us-east-2.amazonaws.com"
+	testArtifact              = testHost + "/foo:latest"
+	testArtifactWithoutRegion = "public.ecr.aws/foo/foo:latest"
 )
 
 // Verifies that awsEcrBasicAuthProvider is properly constructed by mocking EcrAuthToken
 
-func mockAuthData() types.AuthorizationData {
+func mockAuthProvider() awsEcrBasicAuthProvider {
 	// Setup
+	ecrAuthToken := EcrAuthToken{}
+	ecrAuthToken.AuthData = make(map[string]types.AuthorizationData)
+
 	creds := []string{testUsername, testPassword}
 	encoded := base64.StdEncoding.EncodeToString([]byte(strings.Join(creds, ":")))
 
 	expiry := aws.Time(time.Now().Add(time.Minute * 10))
 
-	return types.AuthorizationData{
+	ecrAuthToken.AuthData[testHost] = types.AuthorizationData{
 		AuthorizationToken: aws.String(encoded),
 		ExpiresAt:          expiry,
 		ProxyEndpoint:      aws.String(testProxy),
 	}
+
+	return awsEcrBasicAuthProvider{
+		ecrAuthToken: ecrAuthToken,
+		providerName: awsEcrAuthProviderName,
+	}
 }
 
 func TestAwsEcrBasicAuthProvider_Create(t *testing.T) {
@@ -64,13 +75,7 @@ func TestAwsEcrBasicAuthProvider_Create(t *testing.T) {
 }
 
 func TestAwsEcrBasicAuthProvider_Enabled(t *testing.T) {
-	ecrAuthToken := EcrAuthToken{}
-	ecrAuthToken.AuthData = make(map[string]types.AuthorizationData)
-	ecrAuthToken.AuthData[testHost] = mockAuthData()
-	authProvider := awsEcrBasicAuthProvider{
-		ecrAuthToken: ecrAuthToken,
-		providerName: awsEcrAuthProviderName,
-	}
+	authProvider := mockAuthProvider()
 
 	ctx := context.Background()
 
@@ -83,3 +88,38 @@ func TestAwsEcrBasicAuthProvider_Enabled(t *testing.T) {
 		t.Fatal("enabled should have returned false but returned true")
 	}
 }
+
+func TestAwsEcrBasicAuthProvider_ProvidesWithArtifact(t *testing.T) {
+	authProvider := mockAuthProvider()
+
+	_, err := authProvider.Provide(context.TODO(), testArtifact)
+	if err != nil {
+		t.Fatalf("encountered error: %+v", err)
+	}
+}
+
+func TestAwsEcrBasicAuthProvider_ProvidesWithHost(t *testing.T) {
+	authProvider := mockAuthProvider()
+
+	_, err := authProvider.Provide(context.TODO(), testHost)
+	if err != nil {
+		t.Fatalf("encountered error: %+v", err)
+	}
+}
+
+func TestAwsEcrBasicAuthProvider_GetAuthTokenWithoutRegion(t *testing.T) {
+	authProvider := mockAuthProvider()
+
+	os.Setenv("AWS_REGION", "placeholder")
+	os.Setenv("AWS_ROLE_ARN", "placeholder")
+	os.Setenv("AWS_WEB_IDENTITY_TOKEN_FILE", "placeholder")
+	_, err := authProvider.getEcrAuthToken(testArtifactWithoutRegion)
+	if err == nil {
+		t.Fatalf("expected error: %+v", err)
+	}
+
+	expectedMessage := "failed to get region from image"
+	if err.Error() != expectedMessage {
+		t.Fatalf("expected message: %s, instead got error: %s", expectedMessage, err.Error())
+	}
+}
diff --git a/pkg/verifier/notaryv2/pluginmanager_test.go b/pkg/verifier/notaryv2/pluginmanager_test.go
new file mode 100644
index 0000000..43b6f06
--- /dev/null
+++ b/pkg/verifier/notaryv2/pluginmanager_test.go
@@ -0,0 +1,79 @@
+package notaryv2
+
+import (
+	"context"
+	"os"
+	"testing"
+)
+
+const (
+	pluginDirectory  = "./pluginmanagertest"
+	ignoredDirectory = "notation-ignored"
+	ignoredFile      = "ignored.file"
+	testPluginName   = "mock.plugin"
+)
+
+func TestMain(m *testing.M) {
+	err := setupTestFiles()
+	code := 1
+	if err == nil {
+		code = m.Run()
+	}
+	cleanupTestFiles()
+	os.Exit(code)
+}
+
+func setupTestFiles() error {
+	err := os.Mkdir(pluginDirectory, 0700)
+	if err != nil {
+		return err
+	}
+
+	err = os.Mkdir(pluginDirectory+"/"+ignoredDirectory, 0700)
+	if err != nil {
+		return err
+	}
+
+	err = os.WriteFile(pluginDirectory+"/"+notationPluginPrefix+testPluginName, []byte(""), 0600)
+	if err != nil {
+		return err
+	}
+
+	err = os.WriteFile(pluginDirectory+"/"+ignoredFile, []byte(""), 0600)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func cleanupTestFiles() {
+	os.RemoveAll(pluginDirectory)
+}
+
+func TestPluginManagerGet(t *testing.T) {
+	pluginManager := NewRatifyPluginManager(pluginDirectory)
+
+	_, err := pluginManager.Get(context.TODO(), testPluginName)
+	if err != nil {
+		t.Errorf("unexpected error: %v", err)
+	}
+}
+
+func TestPluginManagerList(t *testing.T) {
+	pluginManager := NewRatifyPluginManager(pluginDirectory)
+
+	pluginList, err := pluginManager.List(context.TODO())
+	if err != nil {
+		t.Errorf("unexpected error: %v", err)
+	}
+
+	if len(pluginList) != 1 {
+		t.Errorf("expected to find exactly one plugin, instead found %d", len(pluginList))
+		t.Fatalf("plugin list: %+v", pluginList)
+	}
+
+	if pluginList[0] != testPluginName {
+		t.Errorf("expected to find plugin named %s, instead found %s", testPluginName, pluginList[0])
+	}
+}