LoginSignup
0
0

私的サーバー構築日誌:Samba in Docker

Posted at

能書き

私的サーバー構築日誌:仕切り直しからの自宅サーバー構築の続きです。

Sambaでファイルサーバーを立てて、Windowsからファイルアクセスできるようにします。環境を汚すのがイヤだったので、SambaサーバーはDockerに閉じ込めます。同じ理由で、LDAPとの連携は諦めました。SambaはLDAPに何やら書き込むらしいので。

パスワードなども平文でdocker-compose.ymlファイルに格納される手順になります。気になる方は、今回の手順は避けて下さい。

参考文献

準備

共有ディレクトリ

/srv/sambaを作って共有ディレクトリとします。

サーバー側
cd /srv
sudo mkdir samba
サーバー側
sudo chown $USER: samba

docker-compose.yml

サーバー側
cd
mkdir docker-samba
cd docker-samba
サーバー側
curl -O https://raw.githubusercontent.com/ServerContainers/samba/master/docker-compose.yml

例によってパッチを用意しました。用意すべきアカウントの追加などは適宜対応して下さい。環境変数などの設定に関してはこちらの本家説明を参照して下さい。説明は英語なので自動翻訳でどうぞ。

サーバー側
ACCOUNT=taro
SURNAME=familyname
PASSWORD=Ma9H%6jg
USERID=10000
GROUPID=10000
サーバー側
cat <<___ >samba.patch
9c9
<     restart: always
---
>     restart: unless-stopped
10,11d9
<     # note that this network_mode makes it super easy (especially for zeroconf) but is not as safe as exposing ports directly
<     # more about that here: https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation#hostnetwork
13,15d10
<     # uncomment to solve bug: https://github.com/ServerContainers/samba/issues/50 - wsdd2 only - not needed for samba
<     #cap_add:
<     #  - CAP_NET_ADMIN
22,26d16
<       # uncomment to disable optional services
<       #WSDD2_DISABLE: 1
<       #AVAHI_DISABLE: 1
<       #NETBIOS_DISABLE: 1
< 
29,42c19,21
<       ACCOUNT_alice: alipass
<       UID_alice: 1000
<       GROUPS_alice: family
< 
<       ACCOUNT_bob: bobpass
<       UID_bob: 1001
<       GROUPS_bob: family
< 
<       # example for hashed password (user: foo | password: bar) - generated using create-hash.sh script.
<       ACCOUNT_foo: "foo:1000:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:86C156FC198B358CCCF6278D8BD49B6A:[U          ]:LCT-61B0859A:"
<       UID_foo: 1002
<       GROUPS_foo: family
< 
<       SAMBA_VOLUME_CONFIG_shared_home: "[Home]; path=/shares/homes/%U; valid users = alice, bob, foo; guest ok = no; read only = no; browseable = yes"
---
>       ACCOUNT_$ACCOUNT: $PASSWORD
>       UID_$ACCOUNT: $USERID
>       GROUPS_$ACCOUNT: $SURNAME
44,45c23
<       SAMBA_VOLUME_CONFIG_aliceonly: "[Alice Share]; path=/shares/alice; valid users = alice; guest ok = no; read only = no; browseable = yes"
<       SAMBA_VOLUME_CONFIG_alicehidden: "[Alice Hidden Share]; path=/shares/alice-hidden; valid users = alice; guest ok = no; read only = no; browseable = no"
---
>       SAMBA_VOLUME_CONFIG_${ACCOUNT}only: "[$ACCOUNT]; path=/shares/$ACCOUNT; valid users = $ACCOUNT; guest ok = no; read only = no; browseable = yes"
47,52d24
<       SAMBA_VOLUME_CONFIG_bobonly: "[Bob Share]; path=/shares/bob; valid users = bob; guest ok = no; read only = no; browseable = yes"
< 
<       SAMBA_VOLUME_CONFIG_public: "[Public]; path=/shares/public; valid users = alice, bob, foo; guest ok = no; read only = no; browseable = yes; force group = family"
<       SAMBA_VOLUME_CONFIG_public_ro: "[Public ReadOnly]; path=/shares/public; guest ok = yes; read only = yes; browseable = yes; force group = family"
< 
<       SAMBA_VOLUME_CONFIG_timemachine: "[TimeMachine]; path=/shares/timemachine/%U; valid users = alice, bob, foo; guest ok = no; read only = no; browseable = yes; fruit:time machine = yes; fruit:time machine max size = 500G"
54c26
<       - /etc/avahi/services/:/external/avahi
---
>       - ./etc_avahi_services/:/external/avahi
57,63c29
<       - ./shares/alice:/shares/alice
<       - ./shares/alice-hidden:/shares/alice-hidden
<       - ./shares/bob:/shares/bob
<       - ./shares/public:/shares/public
<       - ./shares/homes:/shares/homes
<       - ./shares/timemachine:/shares/timemachine
< 
---
>       - /srv/samba/$ACCOUNT:/shares/$ACCOUNT
___
サーバー側
patch --ignore-whitespace docker-compose.yml <samba.patch

起動と確認

サーバー側
docker compose up -d

共有ディレクトリの所有者をきちんとtaroにしてやらないと、書き込めないようです。

サーバー側
cd /srv/samba
sudo chown $USERID:$GROUPID $ACCOUNT

同じLAN上にあるWindowsマシンから共有の具合を確認します。primary.homeが家庭内LANに設定しているウチのサーバーの名前です。

WindowsクライアントマシンのDOSプロンプト
start \\primary.home

これでユーザーtaroとしてログインすると、taroフォルダが表示され、編集可能になります。

仕舞い

成功が確認できたら、設定ファイルのパッチは不要なので削除しておきましょう。

サーバー側
cd
rm docker-samba/samba.patch

以上、sambaサーバーをDockerコンテナで立てました。これだけなら非常に簡単ですね。これだけなら。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0