in src/s3fs_cred.cpp [772:875]
bool S3fsCred::InitialCredentials()
{
// should be redundant
if(S3fsCurl::IsPublicBucket()){
return true;
}
// access key loading is deferred
if(load_ramrole || IsSetExtCredLib()){
return true;
}
// 1 - keys specified on the command line
if(IsSetAccessKeys(AutoLock::NONE)){
return true;
}
// 2 - was specified on the command line
if(IsSetPasswdFile()){
if(!ReadPasswdFile(AutoLock::NONE)){
return false;
}
return true;
}
// 3 - environment variables
char* OSSACCESSKEYID = getenv("OSSACCESSKEYID") ? getenv("OSSACCESSKEYID") : getenv("OSS_ACCESS_KEY_ID");
char* OSSSECRETACCESSKEY = getenv("OSSSECRETACCESSKEY") ? getenv("OSSSECRETACCESSKEY") : getenv("OSS_ACCESS_KEY_SECRET");
char* OSSSESSIONTOKEN = getenv("OSSSESSIONTOKEN") ? getenv("OSSSESSIONTOKEN") : getenv("OSS_SESSION_TOKEN");
if(OSSACCESSKEYID != NULL || OSSSECRETACCESSKEY != NULL){
if( (OSSACCESSKEYID == NULL && OSSSECRETACCESSKEY != NULL) ||
(OSSACCESSKEYID != NULL && OSSSECRETACCESSKEY == NULL) ){
S3FS_PRN_EXIT("both environment variables OSSACCESSKEYID and OSSSECRETACCESSKEY must be set together.");
return false;
}
S3FS_PRN_INFO2("access key from env variables");
if(OSSSESSIONTOKEN != NULL){
S3FS_PRN_INFO2("session token is available");
if(!SetAccessKeyWithSessionToken(OSSACCESSKEYID, OSSSECRETACCESSKEY, OSSSESSIONTOKEN, AutoLock::NONE)){
S3FS_PRN_EXIT("session token is invalid.");
return false;
}
}else{
S3FS_PRN_INFO2("session token is not available");
if(is_use_session_token){
S3FS_PRN_EXIT("environment variable OSSSESSIONTOKEN is expected to be set.");
return false;
}
}
if(!SetAccessKey(OSSACCESSKEYID, OSSSECRETACCESSKEY, AutoLock::NONE)){
S3FS_PRN_EXIT("if one access key is specified, both keys need to be specified.");
return false;
}
return true;
}
// 3a - from the OSS_CREDENTIAL_FILE environment variable
char* OSS_CREDENTIAL_FILE = getenv("OSS_CREDENTIAL_FILE");
if(OSS_CREDENTIAL_FILE != NULL){
passwd_file = OSS_CREDENTIAL_FILE;
if(IsSetPasswdFile()){
if(!IsReadablePasswdFile()){
S3FS_PRN_EXIT("OSS_CREDENTIAL_FILE: \"%s\" is not readable.", passwd_file.c_str());
return false;
}
if(!ReadPasswdFile(AutoLock::NONE)){
return false;
}
return true;
}
}
// 4 - from the default location in the users home directory
char* HOME = getenv("HOME");
if(HOME != NULL){
passwd_file = HOME;
passwd_file += "/.passwd-ossfs";
if(IsReadablePasswdFile()){
if(!ReadPasswdFile(AutoLock::NONE)){
return false;
}
// It is possible that the user's file was there but
// contained no key pairs i.e. commented out
// in that case, go look in the final location
if(IsSetAccessKeys(AutoLock::NONE)){
return true;
}
}
}
// 5 - from the system default location
passwd_file = DEFAULT_PASSWD_FILE;
if(IsReadablePasswdFile()){
if(!ReadPasswdFile(AutoLock::NONE)){
return false;
}
return true;
}
S3FS_PRN_EXIT("could not determine how to establish security credentials.");
return false;
}