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 align="center" no-gutters class="my-3">
<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-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-col class="py-0" cols="2">
<v-select
@@ -292,9 +284,20 @@
</div>
</v-row>
<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>
<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 :style="{ opacity: !storageEnabled ? 0.25 : 1 }">
<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>Public</strong>: Host path must be whitelisted in config and exists on the host.
</p>
@@ -581,14 +584,16 @@ export default class RoomsCreate extends Vue {
get mountTypes() {
return [
{
text: 'Private',
value: 'private',
},
{
text: 'Template',
value: 'template',
},
...(this.storageEnabled ? [
{
text: 'Private',
value: 'private',
},
{
text: 'Template',
value: 'template',
},
] : []),
{
text: '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)
}
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 {
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")
}
// private container's data
if mount.Type == types.MountPrivate {
switch mount.Type {
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
internalPath := path.Join(manager.config.StorageInternal, privateStoragePath, roomName, hostPath)
if _, err := os.Stat(internalPath); os.IsNotExist(err) {
@@ -332,13 +332,17 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
// prefix host path
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 = true
// prefix host path
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 = mount.Type == types.MountProtected
@@ -354,7 +358,7 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
if !isAllowed {
return "", fmt.Errorf("mount path is not whitelisted in config")
}
} else {
default:
return "", fmt.Errorf("unknown mount type %q", mount.Type)
}