Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
anbox
提交
7a2cef31
A
anbox
项目概览
openeuler
/
anbox
通知
24
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
anbox
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7a2cef31
编写于
1月 03, 2017
作者:
S
Simon Fels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Run container as unprivileged for enhanced security
On the Android side this requires no change with the current setup.
上级
128cc242
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
6 deletion
+47
-6
src/anbox/container/lxc_container.cpp
src/anbox/container/lxc_container.cpp
+42
-2
src/anbox/container/lxc_container.h
src/anbox/container/lxc_container.h
+4
-1
src/anbox/container/management_api_skeleton.cpp
src/anbox/container/management_api_skeleton.cpp
+0
-2
src/anbox/container/service.cpp
src/anbox/container/service.cpp
+1
-1
未找到文件。
src/anbox/container/lxc_container.cpp
浏览文件 @
7a2cef31
...
@@ -35,7 +35,8 @@ namespace fs = boost::filesystem;
...
@@ -35,7 +35,8 @@ namespace fs = boost::filesystem;
namespace
anbox
{
namespace
anbox
{
namespace
container
{
namespace
container
{
LxcContainer
::
LxcContainer
()
:
state_
(
State
::
inactive
),
container_
(
nullptr
)
{
LxcContainer
::
LxcContainer
(
const
network
::
Credentials
&
creds
)
:
state_
(
State
::
inactive
),
container_
(
nullptr
),
creds_
(
creds
)
{
utils
::
ensure_paths
({
utils
::
ensure_paths
({
config
::
container_config_path
(),
config
::
log_path
(),
config
::
container_config_path
(),
config
::
log_path
(),
});
});
...
@@ -49,6 +50,32 @@ LxcContainer::~LxcContainer() {
...
@@ -49,6 +50,32 @@ LxcContainer::~LxcContainer() {
if
(
container_
)
lxc_container_put
(
container_
);
if
(
container_
)
lxc_container_put
(
container_
);
}
}
void
LxcContainer
::
setup_id_maps
()
{
const
auto
base_id
=
100000
;
const
auto
max_id
=
65536
;
set_config_item
(
"lxc.id_map"
,
utils
::
string_format
(
"u 0 %d %d"
,
base_id
,
creds_
.
uid
()
-
1
));
set_config_item
(
"lxc.id_map"
,
utils
::
string_format
(
"g 0 %d %d"
,
base_id
,
creds_
.
gid
()
-
1
));
// We need to bind the user id for the one running the client side
// process as he is the owner of various socket files we bind mount
// into the container.
set_config_item
(
"lxc.id_map"
,
utils
::
string_format
(
"u %d %d 1"
,
creds_
.
uid
(),
creds_
.
uid
()));
set_config_item
(
"lxc.id_map"
,
utils
::
string_format
(
"g %d %d 1"
,
creds_
.
gid
(),
creds_
.
gid
()));
set_config_item
(
"lxc.id_map"
,
utils
::
string_format
(
"u %d %d %d"
,
creds_
.
uid
()
+
1
,
base_id
+
creds_
.
uid
()
+
1
,
max_id
-
creds_
.
uid
()
-
1
));
set_config_item
(
"lxc.id_map"
,
utils
::
string_format
(
"g %d %d %d"
,
creds_
.
uid
()
+
1
,
base_id
+
creds_
.
gid
()
+
1
,
max_id
-
creds_
.
gid
()
-
1
));
}
void
LxcContainer
::
start
(
const
Configuration
&
configuration
)
{
void
LxcContainer
::
start
(
const
Configuration
&
configuration
)
{
if
(
getuid
()
!=
0
)
if
(
getuid
()
!=
0
)
BOOST_THROW_EXCEPTION
(
BOOST_THROW_EXCEPTION
(
...
@@ -128,7 +155,20 @@ void LxcContainer::start(const Configuration &configuration) {
...
@@ -128,7 +155,20 @@ void LxcContainer::start(const Configuration &configuration) {
set_config_item
(
"lxc.aa_profile"
,
"unconfined"
);
set_config_item
(
"lxc.aa_profile"
,
"unconfined"
);
#endif
#endif
for
(
const
auto
&
bind_mount
:
configuration
.
bind_mounts
)
{
setup_id_maps
();
auto
bind_mounts
=
configuration
.
bind_mounts
;
// Extra bind-mounts for user-namespace setup
bind_mounts
.
insert
({
"/dev/console"
,
"dev/console"
});
bind_mounts
.
insert
({
"/dev/full"
,
"dev/full"
});
bind_mounts
.
insert
({
"/dev/null"
,
"dev/null"
});
bind_mounts
.
insert
({
"/dev/random"
,
"dev/random"
});
bind_mounts
.
insert
({
"/dev/tty"
,
"dev/tty"
});
bind_mounts
.
insert
({
"/dev/urandom"
,
"dev/urandom"
});
bind_mounts
.
insert
({
"/dev/zero"
,
"dev/zero"
});
for
(
const
auto
&
bind_mount
:
bind_mounts
)
{
std
::
string
create_type
=
"file"
;
std
::
string
create_type
=
"file"
;
if
(
fs
::
is_directory
(
bind_mount
.
first
))
create_type
=
"dir"
;
if
(
fs
::
is_directory
(
bind_mount
.
first
))
create_type
=
"dir"
;
...
...
src/anbox/container/lxc_container.h
浏览文件 @
7a2cef31
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#define ANBOX_CONTAINER_LXC_CONTAINER_H_
#define ANBOX_CONTAINER_LXC_CONTAINER_H_
#include "anbox/container/container.h"
#include "anbox/container/container.h"
#include "anbox/network/credentials.h"
#include <string>
#include <string>
...
@@ -28,7 +29,7 @@ namespace anbox {
...
@@ -28,7 +29,7 @@ namespace anbox {
namespace
container
{
namespace
container
{
class
LxcContainer
:
public
Container
{
class
LxcContainer
:
public
Container
{
public:
public:
LxcContainer
();
LxcContainer
(
const
network
::
Credentials
&
creds
);
~
LxcContainer
();
~
LxcContainer
();
void
start
(
const
Configuration
&
configuration
)
override
;
void
start
(
const
Configuration
&
configuration
)
override
;
...
@@ -37,9 +38,11 @@ class LxcContainer : public Container {
...
@@ -37,9 +38,11 @@ class LxcContainer : public Container {
private:
private:
void
set_config_item
(
const
std
::
string
&
key
,
const
std
::
string
&
value
);
void
set_config_item
(
const
std
::
string
&
key
,
const
std
::
string
&
value
);
void
setup_id_maps
();
State
state_
;
State
state_
;
lxc_container
*
container_
;
lxc_container
*
container_
;
network
::
Credentials
creds_
;
};
};
}
// namespace container
}
// namespace container
}
// namespace anbox
}
// namespace anbox
...
...
src/anbox/container/management_api_skeleton.cpp
浏览文件 @
7a2cef31
...
@@ -59,8 +59,6 @@ void ManagementApiSkeleton::start_container(
...
@@ -59,8 +59,6 @@ void ManagementApiSkeleton::start_container(
utils
::
string_format
(
"Failed to start container: %s"
,
err
.
what
()));
utils
::
string_format
(
"Failed to start container: %s"
,
err
.
what
()));
}
}
DEBUG
(
""
);
done
->
Run
();
done
->
Run
();
}
}
}
// namespace container
}
// namespace container
...
...
src/anbox/container/service.cpp
浏览文件 @
7a2cef31
...
@@ -77,7 +77,7 @@ void Service::new_client(
...
@@ -77,7 +77,7 @@ void Service::new_client(
auto
pending_calls
=
std
::
make_shared
<
rpc
::
PendingCallCache
>
();
auto
pending_calls
=
std
::
make_shared
<
rpc
::
PendingCallCache
>
();
auto
rpc_channel
=
std
::
make_shared
<
rpc
::
Channel
>
(
pending_calls
,
messenger
);
auto
rpc_channel
=
std
::
make_shared
<
rpc
::
Channel
>
(
pending_calls
,
messenger
);
auto
server
=
std
::
make_shared
<
container
::
ManagementApiSkeleton
>
(
auto
server
=
std
::
make_shared
<
container
::
ManagementApiSkeleton
>
(
pending_calls
,
std
::
make_shared
<
LxcContainer
>
());
pending_calls
,
std
::
make_shared
<
LxcContainer
>
(
messenger
->
creds
()
));
auto
processor
=
std
::
make_shared
<
container
::
ManagementApiMessageProcessor
>
(
auto
processor
=
std
::
make_shared
<
container
::
ManagementApiMessageProcessor
>
(
messenger
,
pending_calls
,
server
);
messenger
,
pending_calls
,
server
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录