# Linux File Permissions for DevOps: From chmod to Kubernetes

Linux access control doesn't disappear when infrastructure moves to containers.

A process still has an identity. A file still has ownership. A mounted volume still has access restrictions.

Understanding this relationship is essential for engineers working with modern infrastructure.

## Start with the process identity

When troubleshooting a permission problem, begin by identifying the account performing the operation.

```bash
id
whoami
```

Next, inspect the resource:

```bash
ls -ld /path/to/directory
ls -l /path/to/file
```

The current shell identity may differ from the application or service identity. Make sure you investigate the actual failing process.

## Decode the access policy

A mode of 640 describes the following ordinary permission bits:

| Identity | Access |
| --- | --- |
| Owner | Read and write |
| Group | Read |
| Others | None |

This can be appropriate for configuration files that an application must read but should not modify.

It is not enough to inspect the number alone. The correct owner and group are equally important.

## Directory traversal matters

A common mistake is inspecting only the final file.

Linux also checks whether the process can traverse the directories leading to it.

Use:

```bash
namei -l /path/to/configuration
```

This can reveal a restrictive parent directory that would otherwise be overlooked.

## SGID for collaboration

Shared deployment directories often need consistent group ownership.

An SGID directory can make newly created entries inherit the directory's group.

A mode such as 2770 is useful in an appropriately configured private team directory.

However, group inheritance doesn't automatically guarantee group write access. The creation mode, umask and applicable ACLs still matter.

## Default permissions and umask

A process's umask removes permission bits during object creation.

A umask of 027 commonly produces:

- Regular files: 640
- Directories: 750

Applications can request more restrictive modes, and default ACLs can also influence the result.

## The Kubernetes connection

Imagine a non-root container that starts successfully but cannot write to its persistent volume.

Changing the application to run as root might hide the immediate symptom while weakening isolation.

A Pod-level security context may help:

```yaml
spec:
  securityContext:
    runAsUser: 10001
    runAsGroup: 10001
    fsGroup: 10001
    fsGroupChangePolicy: OnRootMismatch
```

This is a Pod specification fragment, not a complete deployment manifest.

The effectiveness of fsGroup depends on the volume type and CSI driver. Some drivers handle ownership themselves, and some storage configurations require separate server-side permission management.

## A practical troubleshooting workflow

1. Identify the failing operation.
2. Determine the application's UID and groups.
3. Inspect the target file and parent directories.
4. Verify filesystem and mount restrictions.
5. Change only the permissions or ownership required.
6. Retest using the actual service identity.

Avoid broad recursive changes until you understand their impact.

## Conclusion

The same Linux fundamentals that protect an SSH key also influence access to application configuration and persistent storage.

Tools change. The access-control principles remain relevant.

Explore octal permission calculations, SUID, SGID, sticky bits, interactive exercises and additional examples in the [original Linux file permissions guide](https://blog.naveedkumbhar.com/linux-file-permissions-explained/).

References:

- [Linux path resolution](https://man7.org/linux/man-pages/man7/path_resolution.7.html)
- [Kubernetes security contexts](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/)
