Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S-094の解答が権限不足により失敗する #120

Open
nknytk opened this issue Dec 21, 2021 · 3 comments
Open

S-094の解答が権限不足により失敗する #120

nknytk opened this issue Dec 21, 2021 · 3 comments

Comments

@nknytk
Copy link
Contributor

nknytk commented Dec 21, 2021

事象

実行したセルの内容は下記の通りです。S-093で作成したテーブル名をproduct2としています。

%%sql
COPY product2 TO '/tmp/data/product2.csv' WITH CSV HEADER encoding 'UTF-8'

下記のエラーとなりました。

 * postgresql://padawan:***@db:5432/dsdojo_db
(psycopg2.errors.InsufficientPrivilege) could not open file "/tmp/data/product2.csv" for writing: Permission denied
HINT:  COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.

[SQL: COPY product2 TO '/tmp/data/product2.csv' WITH CSV HEADER encoding 'UTF-8']
(Background on this error at: https://sqlalche.me/e/14/f405)

環境

OS: Ubuntu 20.04
docker: 20.10.12
docker-compose: 1.29.2

@KazuhiroM
Copy link
Contributor

@nknytk リアクション遅くなりました。本件、Windows10とmacOSXで動作確認してみたのですが、どちらもSQLの解答コードはすべて動作しました。

100knocks-preprocess/docker/db/init/1_init.sqlにかかれている以下コードでCOPYコマンドの権限をノック用DBユーザであるpadawanに付与しているのですが、これがうまく実行されていないかもしれません(開発中、この権限の設定が足りず同様のエラーを見たことがあります)。最新版を取得の上、再度環境構築を試みていただけますか?

grant pg_read_server_files to padawan ;
grant pg_write_server_files to padawan ;

@nknytk
Copy link
Contributor Author

nknytk commented Jan 15, 2022

@KazuhiroM 動作確認ありがとうございました。最新版を取得して環境を再構築しましたが、私の環境ではエラーが再現しました。

DBユーザーに対する権限付与は正常に行われており、コンテナ内のpostgresプロセスが/tmp/dataへの書き込み権限を持たないことが原因のようです。コンテナ内で/tmp/dataのオーナーを変更したころ、コードが動作するようになりました。

コードを動作させるまでの様子を載せておきます。

  1. 環境構築直後、Notebook上でCSVファイルの書き込みに失敗
  2. dss-postgresのコンテナ内部の状況を確認
    • postgresのプロセスはpostgresユーザーで動作
    • postgresユーザーはgid=postgres(70), uid=postgres(70)
    • /tmp/dataのオーナーは1000.1000で権限が775のため、postgresプロセスからは書き込みができない
  3. /tmp/dataのオーナーをpostgres.postgresに変更
  4. Notebook上でCSVの書き込みに成功
privelidges.mp4

コンテナ側からマウントしたディレクトリの所有者・権限を変更することは望ましくないと思うので、マウントオプション等で対処できないか調べてみます。

@KazuhiroM
Copy link
Contributor

仔細のご報告ありがとうございます!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants