allow mounts whitelist without storage, fixes #25.

This commit is contained in:
Miroslav Šedivý
2023-04-15 14:37:17 +02:00
parent 9f46df0022
commit 9d16ebbf4d
2 changed files with 37 additions and 28 deletions
+24 -19
View File
@@ -249,16 +249,8 @@
</v-row> </v-row>
<v-row align="center" no-gutters class="my-3"> <v-row align="center" no-gutters class="my-3">
<h2> Mounts </h2> <h2> Mounts </h2>
<v-btn :disabled="!storageEnabled" @click="data.mounts = [ ...data.mounts, { type: 'private', host_path: '', container_path: '' }]" icon color="green"><v-icon>mdi-plus</v-icon></v-btn> <v-btn @click="data.mounts = [ ...data.mounts, { type: storageEnabled ? 'private' : 'public', host_path: '', container_path: '' }]" icon color="green"><v-icon>mdi-plus</v-icon></v-btn>
</v-row> </v-row>
<v-alert
border="left"
type="warning"
v-if="!storageEnabled"
>
<p><strong>Not available!</strong></p>
<p class="mb-0">Mounts are not available, because storage is not enabled.</p>
</v-alert>
<v-row align="center" class="mb-2" v-for="({ type, host_path, container_path }, index) in data.mounts" :key="index"> <v-row align="center" class="mb-2" v-for="({ type, host_path, container_path }, index) in data.mounts" :key="index">
<v-col class="py-0" cols="2"> <v-col class="py-0" cols="2">
<v-select <v-select
@@ -292,9 +284,20 @@
</div> </div>
</v-row> </v-row>
<v-row align="center" no-gutters v-if="data.mounts.length > 0"> <v-row align="center" no-gutters v-if="data.mounts.length > 0">
<v-alert
border="left"
type="warning"
v-if="!storageEnabled"
style="width: 100%"
>
<p><strong>Not all mount types are available!</strong></p>
<p class="mb-0">Private and Template mounts are not available, because storage is not enabled.</p>
</v-alert>
<p> <p>
<strong>Private</strong>: Host path is relative to <code class="mx-1">&lt;storage path&gt;/rooms/&lt;room name&gt;/</code>. <br /> <span :style="{ opacity: !storageEnabled ? 0.25 : 1 }">
<strong>Template</strong>: Host path is relative to <code class="mx-1">&lt;storage path&gt;/templates/</code>, and will be readonly. <br /> <strong>Private</strong>: Host path is relative to <code class="mx-1">&lt;storage path&gt;/rooms/&lt;room name&gt;/</code>. <br />
<strong>Template</strong>: Host path is relative to <code class="mx-1">&lt;storage path&gt;/templates/</code>, and will be readonly. <br />
</span>
<strong>Protected</strong>: Host path must be whitelisted in config and exists on the host, will be readonly. <br /> <strong>Protected</strong>: Host path must be whitelisted in config and exists on the host, will be readonly. <br />
<strong>Public</strong>: Host path must be whitelisted in config and exists on the host. <strong>Public</strong>: Host path must be whitelisted in config and exists on the host.
</p> </p>
@@ -581,14 +584,16 @@ export default class RoomsCreate extends Vue {
get mountTypes() { get mountTypes() {
return [ return [
{ ...(this.storageEnabled ? [
text: 'Private', {
value: 'private', text: 'Private',
}, value: 'private',
{ },
text: 'Template', {
value: 'template', text: 'Template',
}, value: 'template',
},
] : []),
{ {
text: 'Protected', text: 'Protected',
value: 'protected', value: 'protected',
+13 -9
View File
@@ -95,10 +95,6 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
return "", fmt.Errorf("invalid container name, must match %s", dockerNames.RestrictedNameChars) return "", fmt.Errorf("invalid container name, must match %s", dockerNames.RestrictedNameChars)
} }
if !manager.config.StorageEnabled && len(settings.Mounts) > 0 {
return "", fmt.Errorf("mounts cannot be specified, because storage is disabled or unavailable")
}
if in, _ := utils.ArrayIn(settings.NekoImage, manager.config.NekoImages); !in { if in, _ := utils.ArrayIn(settings.NekoImage, manager.config.NekoImages); !in {
return "", fmt.Errorf("invalid neko image") return "", fmt.Errorf("invalid neko image")
} }
@@ -316,8 +312,12 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
return "", fmt.Errorf("mount paths must be absolute") return "", fmt.Errorf("mount paths must be absolute")
} }
// private container's data switch mount.Type {
if mount.Type == types.MountPrivate { case types.MountPrivate:
if !manager.config.StorageEnabled {
return "", fmt.Errorf("private mounts cannot be specified, because storage is disabled or unavailable")
}
// ensure that target exists with correct permissions // ensure that target exists with correct permissions
internalPath := path.Join(manager.config.StorageInternal, privateStoragePath, roomName, hostPath) internalPath := path.Join(manager.config.StorageInternal, privateStoragePath, roomName, hostPath)
if _, err := os.Stat(internalPath); os.IsNotExist(err) { if _, err := os.Stat(internalPath); os.IsNotExist(err) {
@@ -332,13 +332,17 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
// prefix host path // prefix host path
hostPath = path.Join(manager.config.StorageExternal, privateStoragePath, roomName, hostPath) hostPath = path.Join(manager.config.StorageExternal, privateStoragePath, roomName, hostPath)
} else if mount.Type == types.MountTemplate { case types.MountTemplate:
if !manager.config.StorageEnabled {
return "", fmt.Errorf("template mounts cannot be specified, because storage is disabled or unavailable")
}
// readonly template data // readonly template data
readOnly = true readOnly = true
// prefix host path // prefix host path
hostPath = path.Join(manager.config.StorageExternal, templateStoragePath, hostPath) hostPath = path.Join(manager.config.StorageExternal, templateStoragePath, hostPath)
} else if mount.Type == types.MountProtected || mount.Type == types.MountPublic { case types.MountProtected, types.MountPublic:
// readonly if mount type is protected // readonly if mount type is protected
readOnly = mount.Type == types.MountProtected readOnly = mount.Type == types.MountProtected
@@ -354,7 +358,7 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
if !isAllowed { if !isAllowed {
return "", fmt.Errorf("mount path is not whitelisted in config") return "", fmt.Errorf("mount path is not whitelisted in config")
} }
} else { default:
return "", fmt.Errorf("unknown mount type %q", mount.Type) return "", fmt.Errorf("unknown mount type %q", mount.Type)
} }