AIStor Files
Manage exports

mc files export access

Set which machines may mount an export, and with what access.

mc files export access prints or replaces an export's access rules. Access rules decide which machines may mount an export, and whether they get read-write or read-only access. The node applies new rules without disturbing clients that are already mounted.

Rules match machines, not users. Exports use sec=sys: the client states each user's ID, and the gateway trusts it. Root on an allowed machine can take any user ID, and so reach any user's files.

Syntax

mc files export access ALIAS EXPORT             # print the rules
mc files export access ALIAS EXPORT -f FILE     # replace the rules with those in FILE
mc files export access ALIAS EXPORT --clear     # remove every rule

Flags

FlagMeaning
-f FILE, --file FILEReplaces the export's rules with those in FILE. - reads standard input. FILE is a rules file, or the JSON that --json prints.
--clearRemoves every rule, so every client gets the export's access mode.

Without a flag, access prints the rules. -f and --clear cannot be combined.

Without a flag, access prints the rules as a rules file:

mc files export access myaistor carol
# export carol (id 104): 3 access rules, in match order
192.0.2.7,192.0.2.8    rw
*.lab.example.com      ro
198.51.100.0/24        none

-f replaces the whole list. To change one rule, print the list, edit it, and apply it:

mc files export access myaistor carol > rules.txt
$EDITOR rules.txt
mc files export access myaistor carol -f rules.txt
Set 3 access rules on export `carol` (was 3).
Clients matching no rule are denied.

If another change lands between your print and your apply, the last apply wins. mc reports a conflict only when a change lands while the apply runs.

A script can do the same in JSON. It prints the rules with --json, edits the JSON, and applies it with -f:

mc files export access myaistor carol --json > rules.json
mc files export access myaistor carol -f rules.json

To remove every rule, use --clear. Every client then gets the export's access mode. On an export added with the default access mode rw, any client that reaches the node can mount it read-write. To shut out every client instead, apply the single rule * none.

mc files export access myaistor carol --clear
Cleared the access rules of export `carol` (was 3); every client gets rw.

Example: a home directory

Give each user an export of their own, and let only that user's workstation mount it. These steps set up the export carol for the workstation ws-carol.example.com.

  1. Add the export, owned by carol's uid and gid on the workstation, here 1001. Mode 0700 keeps other users out. --access none keeps the export closed until its rule is set.

    mc files export add myaistor carol --pseudo /carol --size 50GiB --access none \
      --root-dir-uid 1001 --root-dir-gid 1001 --root-dir-mode 0700
  2. Let only the workstation mount the export:

    printf 'ws-carol.example.com rw\n' | mc files export access myaistor carol -f -
    Set 1 access rule on export `carol` (was 0).
    Clients matching no rule are denied.
  3. On the workstation, mount the export as the home directory:

    sudo mount -t nfs4 -o vers=4.1 node01.example.com:/carol /home/carol

    To mount it at boot, add a line to /etc/fstab:

    node01.example.com:/carol  /home/carol  nfs4  vers=4.1,_netdev,hard  0 0

Every other machine is denied, because the export has a rule and no catch-all. Root on the workstation becomes the anonymous user on the export, because --squash root is the default.

The rules file

# carol: build hosts read-write, the lab read-only, contractors out
192.0.2.7,192.0.2.8    rw
*.lab.example.com      ro
198.51.100.0/24        none    # a comment can follow a rule
  • A rule is two fields separated by spaces or tabs: the clients, then the access.
  • The access is rw, ro, or none, in lower case.
  • # starts a comment. Blank lines are skipped.
  • The order is the policy. The first rule that matches a client decides its access, so put narrow rules before wide ones. mc does not warn about a rule that an earlier rule hides.
  • A file holds 1 to 1,000 rules, and each client specification appears once.
  • mc checks the whole file before it sends anything, and reports each error with its line number. To remove every rule, use --clear, not an empty file.

Client specifications

The clients field is one or more specifications, separated by commas without spaces:

FormExampleMatches
Every client*Any client. Use * alone.
IPv4 address203.0.113.7That host.
IPv4 network203.0.113.0/24The network. Host bits must be zero.
IPv6 address2001:db8::7That host.
IPv6 network2001:db8::/64The network.
Hostnamebuild01.example.comThat host. The serving node resolves the name.
Hostname pattern*.lab.example.comNames that match *, ?, or [...]. Matching is case-sensitive.
Netgroup@contractorsMembers of the netgroup, by the client's host name.

A pattern matches the client's address as text and its reverse DNS name. On a shell command line, quote a specification that holds *, ?, or [.

mc refuses a specification the gateway would misread, such as 0.0.0.0 (write * instead), and names the line.

The serving node resolves a hostname when it loads the rules. If a name does not resolve, the apply fails, the old rules stay in force, and mc names the node and the name.

Who gets in

Once an export has a rule, a client that matches no rule is denied. The export's access mode no longer applies. To keep an export open to everyone except a few, end the file with a catch-all:

203.0.113.9     none
*            rw

An export with no rules gives every client the access mode set at add with --access.

The printed rules can differ in spelling from the file you applied. mc stores each specification in one normal form, so a hostname can print in lower case, and a /32 network as a plain address. The rules and their order do not change.

mc files export info also shows the rules, numbered in match order.