Skip to content

Commit a829780

Browse files
committed
feat: add publicAccess config for providerS3
1 parent 071b63f commit a829780

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

packages/provider-s3/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ type ProviderConfig = {
4646
* The time in seconds for the presigned URL to expire. By default, it is 24 hours.
4747
*/
4848
linkExpirationTime?: number;
49+
/**
50+
* If true, the provider will not sign requests and will try to access the S3 bucket without authentication.
51+
*/
52+
publicAccess?: boolean;
4953
};
5054
```
5155

@@ -87,6 +91,22 @@ export default {
8791
};
8892
```
8993

94+
### Public S3 Bucket
95+
96+
```ts
97+
// rock.config.mjs
98+
import { providerS3 } from '@rock-js/provider-s3';
99+
100+
export default {
101+
// ...
102+
remoteCacheProvider: providerS3({
103+
bucket: 'your-public-bucket',
104+
region: 'your-region',
105+
publicAccess: true, // Access public bucket without authentication
106+
}),
107+
};
108+
```
109+
90110
## Documentation
91111

92112
For detailed documentation about Rock and its tools, visit [Rock Documentation](https://rockjs.dev)

packages/provider-s3/src/__tests__/providerS3.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ test('providerS3 supports R2', async () => {
214214
]);
215215
});
216216

217-
test('providerS3 supports public access without credentials', async () => {
217+
test('providerS3 supports public access', async () => {
218218
(clientS3.S3Client as ReturnType<typeof vi.fn>).mockClear();
219219
const mockSend = (clientS3 as any).mockSend;
220220
const mockStream = {
@@ -232,6 +232,7 @@ test('providerS3 supports public access without credentials', async () => {
232232
const cacheProvider = providerS3({
233233
bucket: 'test-bucket',
234234
region: 'us-east-1',
235+
publicAccess: true,
235236
})();
236237

237238
expect(clientS3.S3Client).toHaveBeenCalledWith(

packages/provider-s3/src/lib/providerS3.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ type ProviderConfig = {
6565
* External ID when assuming a role (for additional security).
6666
*/
6767
externalId?: string;
68+
/**
69+
* If true, the provider will not sign requests and will try to access the S3 bucket without authentication.
70+
*/
71+
publicAccess?: boolean;
6872
};
6973

7074
export class S3BuildCache implements RemoteBuildCache {
@@ -104,8 +108,8 @@ export class S3BuildCache implements RemoteBuildCache {
104108
} else if (config.profile) {
105109
// Use shared config file (e.g. ~/.aws/credentials) with a profile
106110
s3Config.credentials = fromIni({ profile: config.profile });
107-
} else {
108-
// Fallback to public access
111+
} else if (config.publicAccess) {
112+
// Access the S3 bucket without authentication
109113
s3Config.signer = {
110114
sign: async (request) => request,
111115
};

website/src/docs/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ In case you use a different env variable, you can pass it as a `accessKeyId` and
249249
| `directory` | `string` | No | The directory to store artifacts in the S3 server (defaults to `rock-artifacts`) |
250250
| `name` | `string` | No | The display name of the provider (defaults to `S3`) |
251251
| `linkExpirationTime` | `number` | No | The time in seconds for presigned URLs to expire (defaults to 24 hours) |
252+
| `publicAccess` | `boolean`| No | If true, the provider will not sign requests and will try to access the S3 bucket without authentication |
252253

253254
#### Authentication Methods
254255

@@ -259,7 +260,7 @@ The S3 provider supports multiple authentication methods through the underlying
259260
- **AWS credentials file**: Use `~/.aws/credentials` with the `profile` option
260261
- **Role assumption**: Use `roleArn` to assume a different role, optionally with `profile` as source credentials
261262
- **Temporary credentials**: Set `AWS_SESSION_TOKEN` environment variable for temporary credentials
262-
- **Public access**: When no credentials are provided, the provider configures a custom signer that doesn't sign requests, allowing access to public S3 buckets without authentication
263+
- **Public access**: Set `publicAccess: true` to explicitly disable request signing and access public S3 buckets without authentication
263264

264265
#### Cloudflare R2
265266

0 commit comments

Comments
 (0)