|
| 1 | +--- |
| 2 | +title: "Access Control" |
| 3 | +description: "Managing permissions and security in Suga applications" |
| 4 | +--- |
| 5 | + |
| 6 | +Suga's access control model defines which services can access which resources, automatically generating appropriate IAM policies or service account permissions. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## How Access Control Works |
| 11 | + |
| 12 | +Access is granted through the `access` property on resources, which can be modified in your project's `suga.yaml` or through the visual editor with the `suga edit` CLI command. |
| 13 | + |
| 14 | +```yaml |
| 15 | +buckets: |
| 16 | + uploads: |
| 17 | + access: |
| 18 | + api: [read, write] # API service can read and write |
| 19 | + worker: [read, delete] # Worker can read and delete |
| 20 | + |
| 21 | +databases: |
| 22 | + main: |
| 23 | + access: |
| 24 | + api: [query] # API can query database |
| 25 | +``` |
| 26 | +
|
| 27 | +When you deploy, Suga generates: |
| 28 | +- **IAM policies** (AWS) with least-privilege permissions |
| 29 | +- **Service account bindings** (GCP) with appropriate roles |
| 30 | +- **Network security rules** allowing service-to-resource communication |
| 31 | +
|
| 32 | +## Permission Types |
| 33 | +
|
| 34 | +### Bucket Permissions |
| 35 | +
|
| 36 | +- `read` - Download/read objects |
| 37 | +- `write` - Upload/write objects |
| 38 | +- `delete` - Delete objects |
| 39 | +- `all` - Shorthand for read, write, delete |
| 40 | + |
| 41 | +```yaml |
| 42 | +buckets: |
| 43 | + data: |
| 44 | + access: |
| 45 | + uploader: [write] |
| 46 | + processor: [read, delete] |
| 47 | + api: [read] |
| 48 | +``` |
| 49 | + |
| 50 | +### Database Permissions |
| 51 | + |
| 52 | +- `query` - Full SQL access (SELECT, INSERT, UPDATE, DELETE) |
| 53 | + |
| 54 | +```yaml |
| 55 | +databases: |
| 56 | + main: |
| 57 | + access: |
| 58 | + api: [query] |
| 59 | + analytics: [query] |
| 60 | +``` |
| 61 | + |
| 62 | +## Least Privilege |
| 63 | + |
| 64 | +Suga encourages and follows the principle of least privilege: |
| 65 | +- By default, services cannot access other resources |
| 66 | +- Services only get permissions they need |
| 67 | +- No wildcards or overly broad policies |
| 68 | +- Separate identities per service |
| 69 | + |
| 70 | +When using the standard Suga AWS Platforms (`suga/aws`), here is an example of the kind of IAM policy that will be generated: |
| 71 | + |
| 72 | +```json |
| 73 | +{ |
| 74 | + "Version": "2012-10-17", |
| 75 | + "Statement": [ |
| 76 | + { |
| 77 | + "Effect": "Allow", |
| 78 | + "Action": [ |
| 79 | + "s3:GetObject", |
| 80 | + "s3:PutObject" |
| 81 | + ], |
| 82 | + "Resource": "arn:aws:s3:::my-app-uploads/*" |
| 83 | + } |
| 84 | + ] |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +<Note> |
| 89 | + If you use your own Suga [resource plugins](/foundations/plugins), you're free to construct the IAM, roles, etc. as you see fit. |
| 90 | +</Note> |
| 91 | + |
| 92 | +## Best Practices |
| 93 | + |
| 94 | +1. **Grant minimum permissions** - Only what each service needs |
| 95 | +2. **Separate services** - Different services for different roles |
| 96 | +3. **Review access patterns** - Regularly audit who accesses what |
| 97 | +4. **Use read-only when possible** - Many services only need read access |
| 98 | + |
| 99 | +## Learn More |
| 100 | + |
| 101 | +<CardGroup cols={2}> |
| 102 | + <Card title="Services" icon="server" href="/develop/services"> |
| 103 | + Service configuration |
| 104 | + </Card> |
| 105 | + |
| 106 | + <Card title="Buckets" icon="box" href="/develop/buckets"> |
| 107 | + Bucket permissions |
| 108 | + </Card> |
| 109 | + |
| 110 | + <Card title="Databases" icon="database" href="/develop/databases"> |
| 111 | + Database access |
| 112 | + </Card> |
| 113 | + |
| 114 | + <Card title="AWS Deployment" icon="aws" href="/deploy/aws"> |
| 115 | + AWS IAM details |
| 116 | + </Card> |
| 117 | +</CardGroup> |
0 commit comments