Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
bf0b9c1e
Unverified
Commit
bf0b9c1e
authored
Oct 27, 2020
by
Christian Brauner
Committed by
GitHub
Oct 27, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3567 from blenk92/lxc-attach-selinux
lxc-attach: Enable setting the SELinux context
parents
a093bb0f
8455e39e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
2 deletions
+16
-2
attach.c
src/lxc/attach.c
+3
-2
attach_options.h
src/lxc/attach_options.h
+3
-0
lxc_attach.c
src/lxc/tools/lxc_attach.c
+10
-0
No files found.
src/lxc/attach.c
View file @
bf0b9c1e
...
@@ -657,6 +657,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
...
@@ -657,6 +657,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
bool
needs_lsm
=
(
options
->
namespaces
&
CLONE_NEWNS
)
&&
bool
needs_lsm
=
(
options
->
namespaces
&
CLONE_NEWNS
)
&&
(
options
->
attach_flags
&
LXC_ATTACH_LSM
)
&&
(
options
->
attach_flags
&
LXC_ATTACH_LSM
)
&&
init_ctx
->
lsm_label
;
init_ctx
->
lsm_label
;
char
*
lsm_label
=
NULL
;
/* A description of the purpose of this functionality is provided in the
/* A description of the purpose of this functionality is provided in the
* lxc-attach(1) manual page. We have to remount here and not in the
* lxc-attach(1) manual page. We have to remount here and not in the
...
@@ -778,9 +779,9 @@ static int attach_child_main(struct attach_clone_payload *payload)
...
@@ -778,9 +779,9 @@ static int attach_child_main(struct attach_clone_payload *payload)
/* Change into our new LSM profile. */
/* Change into our new LSM profile. */
on_exec
=
options
->
attach_flags
&
LXC_ATTACH_LSM_EXEC
?
true
:
false
;
on_exec
=
options
->
attach_flags
&
LXC_ATTACH_LSM_EXEC
?
true
:
false
;
lsm_label
=
options
->
lsm_label
?
options
->
lsm_label
:
init_ctx
->
lsm_label
;
ret
=
init_ctx
->
lsm_ops
->
process_label_set_at
(
init_ctx
->
lsm_ops
,
lsm_fd
,
ret
=
init_ctx
->
lsm_ops
->
process_label_set_at
(
init_ctx
->
lsm_ops
,
lsm_fd
,
init_ctx
->
lsm_label
,
on_exec
);
lsm_label
,
on_exec
);
close
(
lsm_fd
);
close
(
lsm_fd
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
on_error
;
goto
on_error
;
...
...
src/lxc/attach_options.h
View file @
bf0b9c1e
...
@@ -113,6 +113,9 @@ typedef struct lxc_attach_options_t {
...
@@ -113,6 +113,9 @@ typedef struct lxc_attach_options_t {
/*! File descriptor to log output. */
/*! File descriptor to log output. */
int
log_fd
;
int
log_fd
;
/*! lsm label to set. */
char
*
lsm_label
;
}
lxc_attach_options_t
;
}
lxc_attach_options_t
;
/*! Default attach options to use */
/*! Default attach options to use */
...
...
src/lxc/tools/lxc_attach.c
View file @
bf0b9c1e
...
@@ -59,6 +59,7 @@ static char **extra_env;
...
@@ -59,6 +59,7 @@ static char **extra_env;
static
ssize_t
extra_env_size
;
static
ssize_t
extra_env_size
;
static
char
**
extra_keep
;
static
char
**
extra_keep
;
static
ssize_t
extra_keep_size
;
static
ssize_t
extra_keep_size
;
static
char
*
selinux_context
=
NULL
;
static
const
struct
option
my_longopts
[]
=
{
static
const
struct
option
my_longopts
[]
=
{
{
"elevated-privileges"
,
optional_argument
,
0
,
'e'
},
{
"elevated-privileges"
,
optional_argument
,
0
,
'e'
},
...
@@ -74,6 +75,7 @@ static const struct option my_longopts[] = {
...
@@ -74,6 +75,7 @@ static const struct option my_longopts[] = {
{
"rcfile"
,
required_argument
,
0
,
'f'
},
{
"rcfile"
,
required_argument
,
0
,
'f'
},
{
"uid"
,
required_argument
,
0
,
'u'
},
{
"uid"
,
required_argument
,
0
,
'u'
},
{
"gid"
,
required_argument
,
0
,
'g'
},
{
"gid"
,
required_argument
,
0
,
'g'
},
{
"context"
,
required_argument
,
0
,
'c'
},
LXC_COMMON_OPTIONS
LXC_COMMON_OPTIONS
};
};
...
@@ -126,6 +128,8 @@ Options :\n\
...
@@ -126,6 +128,8 @@ Options :\n\
Load configuration file FILE
\n
\
Load configuration file FILE
\n
\
-u, --uid=UID Execute COMMAND with UID inside the container
\n
\
-u, --uid=UID Execute COMMAND with UID inside the container
\n
\
-g, --gid=GID Execute COMMAND with GID inside the container
\n
\
-g, --gid=GID Execute COMMAND with GID inside the container
\n
\
-c, --context=context
\n
\
SELinux Context to transition into
\n
\
"
,
"
,
.
options
=
my_longopts
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
parser
=
my_parser
,
...
@@ -201,6 +205,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
...
@@ -201,6 +205,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
if
(
lxc_safe_uint
(
arg
,
&
args
->
gid
)
<
0
)
if
(
lxc_safe_uint
(
arg
,
&
args
->
gid
)
<
0
)
return
-
1
;
return
-
1
;
break
;
break
;
case
'c'
:
selinux_context
=
arg
;
break
;
}
}
return
0
;
return
0
;
...
@@ -353,6 +360,9 @@ int main(int argc, char *argv[])
...
@@ -353,6 +360,9 @@ int main(int argc, char *argv[])
if
(
my_args
.
gid
!=
LXC_INVALID_GID
)
if
(
my_args
.
gid
!=
LXC_INVALID_GID
)
attach_options
.
gid
=
my_args
.
gid
;
attach_options
.
gid
=
my_args
.
gid
;
// selinux_context will be NULL if not set
attach_options
.
lsm_label
=
selinux_context
;
if
(
command
.
program
)
{
if
(
command
.
program
)
{
ret
=
c
->
attach_run_wait
(
c
,
&
attach_options
,
command
.
program
,
ret
=
c
->
attach_run_wait
(
c
,
&
attach_options
,
command
.
program
,
(
const
char
**
)
command
.
argv
);
(
const
char
**
)
command
.
argv
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment