You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by 小嶋恒 <ka...@gmail.com> on 2023/07/15 08:16:30 UTC
Running Solr as an arbitrary user
Hello,
I use solr-docker 9.2.1.
It works with the user “solr” (default) but does not work with other users.
I run the below docker-compose.yml code with the command “docker compose up":
#########
version: ‘3’
services:
solr:
image: solr:9.2.1
user: “${UID:?}:${GID:?}”
#########
Please replace ${UID:?} and ${GID:?} with your UID and GID.
Above code failed and displayed:
Cannot write to /var/solr as UID:GID
drwxrwx--- 4 solr root 4096 Jul 15 07:49 /var/solr
Can Solr run with except “solr” user?
Thank you!
Hisashi
Re: Running Solr as an arbitrary user
Posted by Hisashi Kojima <ka...@gmail.com>.
> Yes, you'll have to edit and rebuild every time.
> you don't have to do that often.
> Basically, if you have a single self-contained stand-alone daemon, and
> all it needs is to write to a mounted volume, all you need is for the
> UID:GID that the daemon runs as to match the UID:GID on the volume.
> Solr is not a single self-contained stand-alone daemon, there's a bit
> more to it. So you can't do that, or at least not easily.
OK. Thank you for your answer.
Hisashi
2023年7月16日(日) 11:30 dmitri maziuk <dm...@gmail.com>:
> On 2023-07-15 7:10 PM, Hisashi Kojima wrote:
> >
> > FYI, MySQL and PostgreSQL images support an arbitrary user other than
> root.
> >
>
> Basically, if you have a single self-contained stand-alone daemon, and
> all it needs is to write to a mounted volume, all you need is for the
> UID:GID that the daemon runs as to match the UID:GID on the volume.
>
> Solr is not a single self-contained stand-alone daemon, there's a bit
> more to it. So you can't do that, or at least not easily.
>
> Dima
>
Re: Running Solr as an arbitrary user
Posted by dmitri maziuk <dm...@gmail.com>.
On 2023-07-15 7:10 PM, Hisashi Kojima wrote:
>
> FYI, MySQL and PostgreSQL images support an arbitrary user other than root.
>
Basically, if you have a single self-contained stand-alone daemon, and
all it needs is to write to a mounted volume, all you need is for the
UID:GID that the daemon runs as to match the UID:GID on the volume.
Solr is not a single self-contained stand-alone daemon, there's a bit
more to it. So you can't do that, or at least not easily.
Dima
Re: Running Solr as an arbitrary user
Posted by Hisashi Kojima <ka...@gmail.com>.
ufuk, thanks for the suggestion.
However, it does not work.
I understand that ENV values in Dockerfile can be overridden when Docker
runs, not Docker builds.
Therefore, "solr" user still owns the /var/solr directory.
> Unless you remove the container completely (not stop, completely remove)
> it would keep indexes written inside the container, not requiring a
volume.
> “docker system prune” or “docker-compose down” would remove all container
data
> so you would lose the index.
That's right, but I need volumes.
Hisashi
2023年7月16日(日) 9:42 ufuk yılmaz <uy...@vivaldi.net.invalid>:
> Unless you remove the container completely (not stop, completely remove)
> it would keep indexes written inside the container, not requiring a volume.
> “docker system prune” or “docker-compose down” would remove all container
> data so you would lose the index.
>
> Instead of rewriting official docker images, wouldn’t just rewriting a new
> Dockerfile which inherits from the official image work?
>
> FROM solr:9.2.1
> ENV SOLR_USER="youruser" \
> SOLR_UID="youruid" \
> SOLR_GROUP="yourgroup" \
> SOLR_GID="yourgid" \
> .. etc
>
> Build an image from that:
> docker image build -t mysolr .
>
> When running it:
> docker run --user "$(id -u):$(id -g)" mysolr -p ….
>
> Installing and running Docker as non-root user is hard enough, if you
> succeeded that solr part should be easier 😊
>
> -ufuk yilmaz
>
>
> Sent from Mail for Windows
>
> From: Hisashi Kojima
> Sent: Sunday, July 16, 2023 3:11 AM
> To: users@solr.apache.org
> Subject: Re: Running Solr as an arbitrary user
>
> I use solr-docker with the server in my university lab.
>
> > Are you using numeric uid/gid in that config, or names?
>
> Yes, I use numeric uid/gid.
>
> > Unless I'm mistaken one of the primary benefits of using docker is that
> > you can avoid having to heavily customize things in each application
> > so that it can coexist with other applications.
>
> I agree.
>
> FYI, MySQL and PostgreSQL images support an arbitrary user other than root.
>
> > Do you have a volume where you map some local path to /var/solr inside
> > the container? If so, you should be able to simply chown the local path
> > for that volume and its contents to the uid/gid that you have
> > configured, and then the permissions inside the container should also be
> > updated so Solr can write to that location.
>
> That's right. However, I cannot use chown command because
> I’m not a root user and have limited permission
> (cannot use chown or su commands) in the university lab’s server.
>
> In my situation, Solr fails to write to volumed directories because
> the directory owner is my non-root user and the writer is also non-root
> user (”solr”).
> If I can replace “solr” user with my non-root user, Solr will also run in
> my situation.
>
> Dima, thanks for the suggestion.
> However, I should rewrite when the Solr "official" image updates, right?
>
> Hisashi
>
> 2023年7月16日(日) 3:23 dmitri maziuk <dm...@gmail.com>:
>
> > On 2023-07-15 11:55 AM, Shawn Heisey wrote:
> > > On 7/15/23 10:30, dmitri maziuk wrote:
> > >> OP needs to pull Dockerfile from upstream, change the numbers in
> > >> ```
> > >> ENV SOLR_USER="solr" \
> > >> SOLR_UID="8983" \
> > >> SOLR_GROUP="solr" \
> > >> SOLR_GID="8983" \
> > >> ...
> > >> ```
> > >
> > > Thanks for that detail! Always learning something new about Solr.
> >
> > Well, this is about docker, strictly speaking. When you look at
> > Dockerfile, there's useradd, groupadd, and chown commands that use the
> > above IUD:GID, as well as "USER $SOLR_UID" at the end (that daemon runs
> > as).
> >
> > That's pretty standard for daemons that won't run as root and/or write
> > to mounted volumes that "other people" need access to. (The latter being
> > the only legitimate reason to run as non-root in a container, but after
> > a couple of decades of "dropping privileges" and "secure coding
> > practices" and all that, most daemons refuse to run as root anymore.)
> >
> > Dima
> >
> >
>
>
RE: Running Solr as an arbitrary user
Posted by ufuk yılmaz <uy...@vivaldi.net.INVALID>.
Unless you remove the container completely (not stop, completely remove) it would keep indexes written inside the container, not requiring a volume.
“docker system prune” or “docker-compose down” would remove all container data so you would lose the index.
Instead of rewriting official docker images, wouldn’t just rewriting a new Dockerfile which inherits from the official image work?
FROM solr:9.2.1
ENV SOLR_USER="youruser" \
SOLR_UID="youruid" \
SOLR_GROUP="yourgroup" \
SOLR_GID="yourgid" \
.. etc
Build an image from that:
docker image build -t mysolr .
When running it:
docker run --user "$(id -u):$(id -g)" mysolr -p ….
Installing and running Docker as non-root user is hard enough, if you succeeded that solr part should be easier 😊
-ufuk yilmaz
Sent from Mail for Windows
From: Hisashi Kojima
Sent: Sunday, July 16, 2023 3:11 AM
To: users@solr.apache.org
Subject: Re: Running Solr as an arbitrary user
I use solr-docker with the server in my university lab.
> Are you using numeric uid/gid in that config, or names?
Yes, I use numeric uid/gid.
> Unless I'm mistaken one of the primary benefits of using docker is that
> you can avoid having to heavily customize things in each application
> so that it can coexist with other applications.
I agree.
FYI, MySQL and PostgreSQL images support an arbitrary user other than root.
> Do you have a volume where you map some local path to /var/solr inside
> the container? If so, you should be able to simply chown the local path
> for that volume and its contents to the uid/gid that you have
> configured, and then the permissions inside the container should also be
> updated so Solr can write to that location.
That's right. However, I cannot use chown command because
I’m not a root user and have limited permission
(cannot use chown or su commands) in the university lab’s server.
In my situation, Solr fails to write to volumed directories because
the directory owner is my non-root user and the writer is also non-root
user (”solr”).
If I can replace “solr” user with my non-root user, Solr will also run in
my situation.
Dima, thanks for the suggestion.
However, I should rewrite when the Solr "official" image updates, right?
Hisashi
2023年7月16日(日) 3:23 dmitri maziuk <dm...@gmail.com>:
> On 2023-07-15 11:55 AM, Shawn Heisey wrote:
> > On 7/15/23 10:30, dmitri maziuk wrote:
> >> OP needs to pull Dockerfile from upstream, change the numbers in
> >> ```
> >> ENV SOLR_USER="solr" \
> >> SOLR_UID="8983" \
> >> SOLR_GROUP="solr" \
> >> SOLR_GID="8983" \
> >> ...
> >> ```
> >
> > Thanks for that detail! Always learning something new about Solr.
>
> Well, this is about docker, strictly speaking. When you look at
> Dockerfile, there's useradd, groupadd, and chown commands that use the
> above IUD:GID, as well as "USER $SOLR_UID" at the end (that daemon runs
> as).
>
> That's pretty standard for daemons that won't run as root and/or write
> to mounted volumes that "other people" need access to. (The latter being
> the only legitimate reason to run as non-root in a container, but after
> a couple of decades of "dropping privileges" and "secure coding
> practices" and all that, most daemons refuse to run as root anymore.)
>
> Dima
>
>
--
//////////////////////////////////////////////////////////////////////////////
佐賀大学大学院 理工学研究科 博士後期課程2年
小嶋 恒(こじま ひさし)
Tel: 080-8397-5844
Mail: kakujo.hk@gmail.com <ma...@gmail.com>
//////////////////////////////////////////////////////////////////////////////
Re: Running Solr as an arbitrary user
Posted by dmitri maziuk <dm...@gmail.com>.
On 2023-07-15 7:10 PM, Hisashi Kojima wrote:
...
> Dima, thanks for the suggestion.
> However, I should rewrite when the Solr "official" image updates, right?
Yes, you'll have to edit and rebuild every time. FWIW you don't have to
update often, e.g. we were running on 6.x for years until upgrading to
8.11, we plan to upgrade to 9.something, but not very soon. I.e. you
don't have to do that often.
Dima
Re: Running Solr as an arbitrary user
Posted by Hisashi Kojima <ka...@gmail.com>.
I use solr-docker with the server in my university lab.
> Are you using numeric uid/gid in that config, or names?
Yes, I use numeric uid/gid.
> Unless I'm mistaken one of the primary benefits of using docker is that
> you can avoid having to heavily customize things in each application
> so that it can coexist with other applications.
I agree.
FYI, MySQL and PostgreSQL images support an arbitrary user other than root.
> Do you have a volume where you map some local path to /var/solr inside
> the container? If so, you should be able to simply chown the local path
> for that volume and its contents to the uid/gid that you have
> configured, and then the permissions inside the container should also be
> updated so Solr can write to that location.
That's right. However, I cannot use chown command because
I’m not a root user and have limited permission
(cannot use chown or su commands) in the university lab’s server.
In my situation, Solr fails to write to volumed directories because
the directory owner is my non-root user and the writer is also non-root
user (”solr”).
If I can replace “solr” user with my non-root user, Solr will also run in
my situation.
Dima, thanks for the suggestion.
However, I should rewrite when the Solr "official" image updates, right?
Hisashi
2023年7月16日(日) 3:23 dmitri maziuk <dm...@gmail.com>:
> On 2023-07-15 11:55 AM, Shawn Heisey wrote:
> > On 7/15/23 10:30, dmitri maziuk wrote:
> >> OP needs to pull Dockerfile from upstream, change the numbers in
> >> ```
> >> ENV SOLR_USER="solr" \
> >> SOLR_UID="8983" \
> >> SOLR_GROUP="solr" \
> >> SOLR_GID="8983" \
> >> ...
> >> ```
> >
> > Thanks for that detail! Always learning something new about Solr.
>
> Well, this is about docker, strictly speaking. When you look at
> Dockerfile, there's useradd, groupadd, and chown commands that use the
> above IUD:GID, as well as "USER $SOLR_UID" at the end (that daemon runs
> as).
>
> That's pretty standard for daemons that won't run as root and/or write
> to mounted volumes that "other people" need access to. (The latter being
> the only legitimate reason to run as non-root in a container, but after
> a couple of decades of "dropping privileges" and "secure coding
> practices" and all that, most daemons refuse to run as root anymore.)
>
> Dima
>
>
--
//////////////////////////////////////////////////////////////////////////////
佐賀大学大学院 理工学研究科 博士後期課程2年
小嶋 恒(こじま ひさし)
Tel: 080-8397-5844
Mail: kakujo.hk@gmail.com <ma...@gmail.com>
//////////////////////////////////////////////////////////////////////////////
Re: Running Solr as an arbitrary user
Posted by dmitri maziuk <dm...@gmail.com>.
On 2023-07-15 11:55 AM, Shawn Heisey wrote:
> On 7/15/23 10:30, dmitri maziuk wrote:
>> OP needs to pull Dockerfile from upstream, change the numbers in
>> ```
>> ENV SOLR_USER="solr" \
>> SOLR_UID="8983" \
>> SOLR_GROUP="solr" \
>> SOLR_GID="8983" \
>> ...
>> ```
>
> Thanks for that detail! Always learning something new about Solr.
Well, this is about docker, strictly speaking. When you look at
Dockerfile, there's useradd, groupadd, and chown commands that use the
above IUD:GID, as well as "USER $SOLR_UID" at the end (that daemon runs as).
That's pretty standard for daemons that won't run as root and/or write
to mounted volumes that "other people" need access to. (The latter being
the only legitimate reason to run as non-root in a container, but after
a couple of decades of "dropping privileges" and "secure coding
practices" and all that, most daemons refuse to run as root anymore.)
Dima
Re: Running Solr as an arbitrary user
Posted by Shawn Heisey <ap...@elyograg.org>.
On 7/15/23 10:30, dmitri maziuk wrote:
> OP needs to pull Dockerfile from upstream, change the numbers in
> ```
> ENV SOLR_USER="solr" \
> SOLR_UID="8983" \
> SOLR_GROUP="solr" \
> SOLR_GID="8983" \
> ...
> ```
Thanks for that detail! Always learning something new about Solr.
Shawn
Re: Running Solr as an arbitrary user
Posted by dmitri maziuk <dm...@gmail.com>.
On 2023-07-15 11:13 AM, Shawn Heisey wrote:
...
> Why do you need to change the user/group?
It is possible that the numbers used by the container are already taken
by something else on the host: there's no set standard, only some linux
conventions that are younger than some unix user accounts.
OP needs to pull Dockerfile from upstream, change the numbers in
```
ENV SOLR_USER="solr" \
SOLR_UID="8983" \
SOLR_GROUP="solr" \
SOLR_GID="8983" \
...
```
(^^^ from the "official" image from Dockerhub) and `docker build` it.
Dima
Re: Running Solr as an arbitrary user
Posted by Shawn Heisey <ap...@elyograg.org>.
On 7/15/23 02:16, 小嶋恒 wrote:
> I use solr-docker 9.2.1.
> It works with the user “solr” (default) but does not work with other users.
>
> I run the below docker-compose.yml code with the command “docker compose up":
>
> #########
>
> version: ‘3’
> services:
> solr:
> image: solr:9.2.1
> user: “${UID:?}:${GID:?}”
>
> #########
>
> Please replace ${UID:?} and ${GID:?} with your UID and GID.
> Above code failed and displayed:
I'll start by saying that I do not know very much about how to use
docker in custom configs. I am blindly finding my way around it but
don't use it heavily, so I am not learning it super quickly.
Are you using numeric uid/gid in that config, or names? I don't know
that it would even be possible to use names.
Do you have a volume where you map some local path to /var/solr inside
the container? If so, you should be able to simply chown the local path
for that volume and its contents to the uid/gid that you have
configured, and then the permissions inside the container should also be
updated so Solr can write to that location.
Why do you need to change the user/group? Unless I'm mistaken one of
the primary benefits of using docker is that you can avoid having to
heavily customize things in each application so that it can coexist with
other applications.
Thanks,
Shawn
Re: Running Solr as an arbitrary user
Posted by dmitri maziuk <dm...@gmail.com>.
On 2023-07-15 3:16 AM, 小嶋恒 wrote:
> Cannot write to /var/solr as UID:GID
> drwxrwx--- 4 solr root 4096 Jul 15 07:49 /var/solr
What are the numbers for $UID, $GID, and solr (`ls -n`)?
Dima