Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the OverrideINIReader for SciTokens #1860

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/XrdSciTokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ default_user = osg
name_mapfile = /path/to/mapfile
```

Duplicate section and settings names (not values) will take the value of the last entry in the file. For example:

```
[Issuer https://chtc.cs.wisc.edu/icecube]
issuer = https://chtc.cs.wisc.edu/icecube
base_path = /icecube/path1

[Issuer https://chtc.cs.wisc.edu/icecube]
issuer = https://chtc.cs.wisc.edu/icecube
base_path = /icecube/path2
```

Will result in a configuration with `issuer = https://chtc.cs.wisc.edu/icecube` and `base_path = /icecube/path2`.

Within the `Global` section, the available attributes are:

- `audience` (optional): A comma separated list of acceptable audiences. The tokens must have an `aud` attribute
Expand Down
48 changes: 47 additions & 1 deletion src/XrdSciTokens/XrdSciTokensAccess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,52 @@ struct IssuerConfig

}

class OverrideINIReader: public INIReader {
public:
OverrideINIReader(XrdSysError log)
: m_log(log) {};
OverrideINIReader(std::string filename, XrdSysError log)
: INIReader(filename),
m_log(log) {

}
OverrideINIReader(FILE *file, XrdSysError log)
: INIReader(file),
m_log(log) {

}
protected:
/**
* Override the ValueHandler function in order override previous values
* For example:
* [Issuer https://chtc.cs.wisc.edu/icecube]
* issuer = https://chtc.cs.wisc.edu/icecube
* base_path = /icecube/path1

* [Issuer https://chtc.cs.wisc.edu/icecube]
* issuer = https://chtc.cs.wisc.edu/icecube
* base_path = /icecube/path2
*
* Will result in a configuration with base_path set to /icecube/path2
*/
inline int ValueHandler(void* user, const char* section, const char* name,
const char* value) {
OverrideINIReader* reader = (OverrideINIReader*)user;
std::string key = MakeKey(section, name);
if (reader->_values[key].size() > 0) {
std::ostringstream os;
os << "Duplicate section and value, overriding previous value: section=" << section << ", name=" << name;
m_log.Log(LogMask::Debug, "INIConfig", os.str().c_str());
}

reader->_values[key] = value;
reader->_sections.insert(section);
return 1;
}

XrdSysError m_log;

};

class XrdAccRules
{
Expand Down Expand Up @@ -1009,7 +1055,7 @@ class XrdAccSciTokens : public XrdAccAuthorize, public XrdSciTokensHelper
}
m_log.Log(LogMask::Info, "Reconfig", "Parsing configuration file:", m_cfg_file.c_str());

INIReader reader(m_cfg_file);
OverrideINIReader reader(m_cfg_file, m_log);
if (reader.ParseError() < 0) {
std::stringstream ss;
ss << "Error opening config file (" << m_cfg_file << "): " << strerror(errno);
Expand Down