> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archil.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Access

> Create disk tokens and S3 credentials, and restrict which IP addresses can mount a disk.

Each disk keeps its own list of who can use it. From the SDKs you can create disk tokens for mounting, authorize an AWS
IAM principal, create S3 credentials for S3 clients, and limit mounts to known IP addresses. For how these credentials
relate to API keys, see [authorization](https://docs.archil.com/concepts/authorization.md).

## Disk tokens

A disk token lets a client mount one disk. `createToken` returns the token once, with an `identifier` for removing it
later.

```typescript TypeScript theme={null}
import * as archil from "disk";

const disk = await archil.getDisk("dsk-abc123");

const { token, identifier } = await disk.createToken("ci-runner");
// Store `token` now. It isn't shown again.

await disk.removeTokenUser(identifier);
```

```python Python theme={null}
import archil

disk = archil.get_disk("dsk-abc123")

user = disk.create_token("ci-runner")
# Store user.token now. It isn't shown again.

disk.remove_token_user(user.identifier)
```

Mount with the token by setting `ARCHIL_MOUNT_TOKEN`. See [token-based disk authorization](https://docs.archil.com/concepts/authorization.md#token-based-disk-authorization).

## IAM principals

To let servers in AWS mount the disk with their IAM identity, add the role or user ARN:

```typescript TypeScript theme={null}
await disk.addUser({ type: "awssts", principal: "arn:aws:iam::123456789012:role/app" });
await disk.removeUser("awssts", "arn:aws:iam::123456789012:role/app");
```

```python Python theme={null}
from archil import AwsStsUser

disk.add_user(AwsStsUser(principal="arn:aws:iam::123456789012:role/app"))
disk.remove_user("awssts", "arn:aws:iam::123456789012:role/app")
```

`disk.authorizedUsers` (`authorized_users` in Python) lists everyone who can use the disk.

## S3 credentials

S3 credentials are an access key pair for AWS SDKs, the AWS CLI, and other S3 clients. They reach every file on the
disk, so keep them on servers and give browsers [share links](https://docs.archil.com/disks/files-and-objects.md#share-a-file) or presigned URLs
instead. The secret key is returned once.

Set `readOnly` to allow only reads, and `ttl` (for example `"24h"`, up to `"8760h"`) or `expiresAt` to make the keys
expire.

```typescript TypeScript theme={null}
const creds = await disk.createS3Credentials({ nickname: "analytics", ttl: "24h", readOnly: true });
console.log(creds.s3AccessKeyId, creds.s3SecretKey);

await disk.removeS3Credentials(creds.s3AccessKeyId);
```

```python Python theme={null}
creds = disk.create_s3_credentials(nickname="analytics", ttl="24h", read_only=True)
print(creds.s3_access_key_id, creds.s3_secret_key)

disk.remove_s3_credentials(creds.s3_access_key_id)
```

Use them with the [S3-compatible API](https://docs.archil.com/protocols/s3-api.md). To read and write files from the SDKs, use the
[object methods](https://docs.archil.com/disks/files-and-objects.md), which authenticate with your API key.

## IP allowlist

An allowlist limits mounts to clients connecting from the listed IP addresses or CIDR ranges. An empty list allows
every address. Changes can take up to a minute to apply everywhere.

```typescript TypeScript theme={null}
await disk.setAllowedIPs(["203.0.113.0/24", "198.51.100.42"]);
await disk.addAllowedIP("192.0.2.10");
await disk.removeAllowedIP("198.51.100.42");
const allowed = await disk.getAllowedIPs();
```

```python Python theme={null}
disk.set_allowed_ips(["203.0.113.0/24", "198.51.100.42"])
disk.add_allowed_ip("192.0.2.10")
disk.remove_allowed_ip("198.51.100.42")
allowed = disk.get_allowed_ips()
```

To create a disk with an allowlist already in place, pass `allowedIps` (`allowed_ips` in Python) to `createDisk`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.