Skip to content

Commit

Permalink
Merge pull request #2900 from Gekko0114/selinux_vagrant
Browse files Browse the repository at this point in the history
selinux: create Vagrantfile for SELinux
  • Loading branch information
YJDoc2 authored Sep 20, 2024
2 parents c889150 + 35b94e4 commit 0b92791
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions experiment/selinux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ Please import and use this project.
```console
$ cargo run
```

You can create an selinux environment via the Vagrantfile.

```console
$ vagrant up
```
19 changes: 19 additions & 0 deletions experiment/selinux/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "generic/centos8"
config.vm.synced_folder '.', '/vagrant/youki', disabled: false

config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 4
end

config.vm.provision "shell", privileged: false, inline: <<-SHELL
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "$HOME/.cargo/env"
sudo sed -i -e 's|^mirrorlist|#mirrorlist|g' -e 's|^#baseurl=http://mirror|baseurl=http://vault|g' /etc/yum.repos.d/CentOS-*repo
sudo yum -y install gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker autoconf wget make
SHELL
end
2 changes: 1 addition & 1 deletion experiment/selinux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() -> Result<()> {
let file_path = Path::new("./test_file.txt");
let _file = File::create(file_path)?;
let selinux_label =
SELinuxLabel::try_from("unconfined_u:object_r:public_content_t:s1".to_string())?;
SELinuxLabel::try_from("system_u:object_r:public_content_t:s0".to_string())?;
SELinux::set_file_label(file_path, selinux_label)?;
let current_label = SELinux::file_label(file_path)?;
println!("file label is {}", current_label);
Expand Down
4 changes: 2 additions & 2 deletions experiment/selinux/src/tools/xattr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
// set_xattr sets extended attributes on a file specified by its path.
fn set_xattr(&self, attr: &str, data: &[u8]) -> Result<(), XattrError> {
let path = self.as_ref();
match rfs::setxattr(path, attr, data, rfs::XattrFlags::CREATE) {
match rfs::setxattr(path, attr, data, rfs::XattrFlags::REPLACE) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
Expand All @@ -50,7 +50,7 @@ where
// lset_xattr sets extended attributes on a symbolic link.
fn lset_xattr(&self, attr: &str, data: &[u8]) -> Result<(), XattrError> {
let path = self.as_ref();
match rfs::lsetxattr(path, attr, data, rfs::XattrFlags::CREATE) {
match rfs::lsetxattr(path, attr, data, rfs::XattrFlags::REPLACE) {
Ok(_) => Ok(()),
Err(e) => {
let errno = e.raw_os_error();
Expand Down

0 comments on commit 0b92791

Please sign in to comment.