Skip to content

Commit 8443330

Browse files
committed
Sketch Permissions for git-config (#386)
It should be possible to control which configuration files are loaded and contribute to the overall configuration. This goes along with at some point allowing to obtain only values which are from trusted configuration files, based on the trust specification passed when loading the configuration.
1 parent f00f4a4 commit 8443330

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-config/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"]
1515

1616
[dependencies]
1717
git-features = { version = "^0.20.0", path = "../git-features"}
18+
git-sec = { version = "^0.1.0", path = "../git-sec" }
19+
1820
dirs = "4"
1921
nom = { version = "7", default_features = false, features = [ "std" ] }
2022
memchr = "2"

git-config/src/lib.rs

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,65 @@ pub mod fs;
5959
pub mod parser;
6060
pub mod values;
6161

62-
// mod de;
63-
// mod ser;
64-
// mod error;
65-
// pub use de::{from_str, Deserializer};
66-
// pub use error::{Error, Result};
67-
// pub use ser::{to_string, Serializer};
62+
mod permissions {
63+
use crate::Permissions;
64+
65+
impl Permissions {
66+
/// Allow everything which usually relates to a fully trusted environment
67+
pub fn all() -> Self {
68+
use git_sec::Permission::*;
69+
Permissions {
70+
system: Allow,
71+
global: Allow,
72+
user: Allow,
73+
repository: Allow,
74+
worktree: Allow,
75+
env: Allow,
76+
includes: Allow,
77+
}
78+
}
79+
80+
/// If in doubt, this configuration can be used to safely load configuration from sources which is usually trusted,
81+
/// that is system and user configuration. Do load any configuration that isn't trusted as it's now owned by the current user.
82+
pub fn secure() -> Self {
83+
use git_sec::Permission::*;
84+
Permissions {
85+
system: Allow,
86+
global: Allow,
87+
user: Allow,
88+
repository: Deny,
89+
worktree: Deny,
90+
env: Allow,
91+
includes: Deny,
92+
}
93+
}
94+
}
95+
}
96+
97+
/// Configure security relevant options when loading a git configuration.
98+
#[derive(Copy, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Hash)]
99+
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
100+
pub struct Permissions {
101+
/// How to use the system configuration.
102+
/// This is defined as `$(prefix)/etc/gitconfig` on unix.
103+
pub system: git_sec::Permission,
104+
/// How to use the global configuration.
105+
/// This is usually `~/.gitconfig`.
106+
pub global: git_sec::Permission,
107+
/// How to use the user configuration.
108+
/// Second user-specific configuration path; if `$XDG_CONFIG_HOME` is not
109+
/// set or empty, `$HOME/.config/git/config` will be used.
110+
pub user: git_sec::Permission,
111+
/// How to use the repository configuration.
112+
pub repository: git_sec::Permission,
113+
/// How to use worktree configuration from `config.worktree`.
114+
// TODO: figure out how this really applies and provide more information here.
115+
pub worktree: git_sec::Permission,
116+
/// How to use the configuration from environment variables.
117+
pub env: git_sec::Permission,
118+
/// What to do when include files are encountered in loaded configuration.
119+
pub includes: git_sec::Permission,
120+
}
68121

69122
#[cfg(test)]
70123
pub mod test_util;

0 commit comments

Comments
 (0)