Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion turbonfs/extern/libnfs
4 changes: 2 additions & 2 deletions turbonfs/inc/nfs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ struct mount_options
// Whether auth is required.
const bool auth;

// AuthType: Currently we only support AzAuthAAD.
const std::string authtype = "AzAuthAAD";
// AuthType: Currently we only support AzAuthAAD and AzAuthNone.
std::string authtype = "AzAuthNone";

// Add any other options as needed.

Expand Down
4 changes: 2 additions & 2 deletions turbonfs/sample-turbo-config.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this from PR

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# "none" as source in the mount command. In that case account and container
# are mandatory, cloud_suffix can be guessed and port is default 2048.
#
account: sjc22prdste06hnfsv3acc1
container: nfsv3test
account: amsprdsty01enfs25
container: testcont

#cloud_suffix: blob.core.windows.net
#cloud_suffix: blob.preprod.core.windows.net
Expand Down
79 changes: 44 additions & 35 deletions turbonfs/src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ std::string get_clientid() {
struct ifaddrs *ifaddr = nullptr;
struct ifaddrs *ifa = nullptr;
char ip[INET_ADDRSTRLEN] = {0};
static std::string client_id = std::to_string(get_current_usecs()) + "-";

/*
* Whatever is encoded here should not exceed the maximum possible that can be
Expand Down Expand Up @@ -60,19 +59,28 @@ std::string get_clientid() {
goto failed_get_clientip;
}

client_id += std::string(ip);

failed_get_clientip:
// Build and cache the client ID only once
static std::string client_id = std::to_string(get_current_usecs()) + "-" + std::string(ip);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random number from /opt/microsoft/aznfs/data/client -- file and concatenate with macaddress.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets create 16bytes random number which is same for all connection and valid till this process is up.


// We cannot send clientid of size more than MAX_IP_LENGTH.
assert(client_id.length() <= MAX_IP_LENGTH);
AZLogDebug("Using clientid {}", client_id);

return client_id;

failed_get_clientip:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed case return empty client_id which means error and mount should fail without client-id.

static std::string fallback_client_id = std::to_string(get_current_usecs()) + "-unknown";
AZLogDebug("Using fallback clientid {}", fallback_client_id);
return fallback_client_id;
}

bool nfs_connection::open()
{
const int nodelay = 1;
std::string client_id;
int ret = -1;
uint64_t n;

// open() must be called only for a closed connection.
assert(nfs_context == nullptr);
Expand Down Expand Up @@ -100,38 +108,39 @@ bool nfs_connection::open()
nfs_destroy_url(url);

if (mo.auth) {
// 16 should be sufficient to hold the version string.
char client_version[16];

[[maybe_unused]]
const uint64_t n = snprintf(client_version, sizeof(client_version),
"%d.%d.%d", AZNFSCLIENT_VERSION_MAJOR,
AZNFSCLIENT_VERSION_MINOR,
AZNFSCLIENT_VERSION_PATCH);
assert(n < sizeof(client_version));

std::string client_id = get_clientid();

assert(!mo.export_path.empty());
assert(!mo.authtype.empty());
assert(strlen(client_version) > 0);
assert(!client_id.empty());

const int ret = nfs_set_auth_context(nfs_context,
mo.export_path.c_str(),
mo.authtype.c_str(),
client_version,
client_id.c_str());
if (ret != 0) {
AZLogError("Failed to set auth values in nfs context, "
"exportpath={} authtype={} "
"clientversion={} clientid={}",
mo.export_path.c_str(),
mo.authtype.c_str(),
client_version,
client_id.c_str());
goto destroy_context;
}
mo.authtype = "AzAuthAAD";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets set this value in constructor.

}

// 16 should be sufficient to hold the version string.
char client_version[16];

n = snprintf(client_version, sizeof(client_version),
"%d.%d.%d", AZNFSCLIENT_VERSION_MAJOR,
AZNFSCLIENT_VERSION_MINOR,
AZNFSCLIENT_VERSION_PATCH);
assert(n < sizeof(client_version));

client_id = get_clientid();

assert(!mo.export_path.empty());
assert(!mo.authtype.empty());
assert(strlen(client_version) > 0);
assert(!client_id.empty());

ret = nfs_set_auth_context(nfs_context,
mo.export_path.c_str(),
mo.authtype.c_str(),
client_version,
client_id.c_str());
if (ret != 0) {
AZLogError("Failed to set auth values in nfs context, "
"exportpath={} authtype={} "
"clientversion={} clientid={}",
mo.export_path.c_str(),
mo.authtype.c_str(),
client_version,
client_id.c_str());
goto destroy_context;
}

/*
Expand Down
37 changes: 37 additions & 0 deletions turbonfs/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,40 @@ auth_token_cb_res *get_auth_token_and_setargs_cb(struct auth_context *auth)
return cb_res;
}

auth_token_cb_res *get_auth_token_and_setargs_cb_none(struct auth_context *auth)
{
if (!auth) {
AZLogError("Null auth_context received");
assert(0);
return nullptr;
}

// Allocate response structure
auth_token_cb_res *cb_res = (auth_token_cb_res *) malloc(sizeof(auth_token_cb_res));
if (!cb_res) {
AZLogError("Failed to allocate memory for auth_token_cb_res");
return nullptr;
}

cb_res->azauth_data = strdup("None");
cb_res->expiry_time = static_cast<uint64_t>(time(NULL))+300;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 300 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you handle in AzAuthNone in rpc_auth_needs_refresh() then you don't need this .


return cb_res;
}

uint64_t set_azauth_res_sc_cb(uint64_t server_cap_map)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this capability code.

{
if (server_cap_map == 1) {
if (!client_started) {
AZLogError("Client not started when get_azauth_res_cb is called");
return -1;
}
}

AZLogInfo("In get_azauth_res_cb %lu",server_cap_map);
return 0;
}

int main(int argc, char *argv[])
{
// Initialize logger first thing.
Expand Down Expand Up @@ -789,7 +823,10 @@ int main(int argc, char *argv[])
if (aznfsc_cfg.auth) {
// Set the auth token callback for this connection if auth is enabled.
set_auth_token_callback(get_auth_token_and_setargs_cb);
} else {
set_auth_token_callback(get_auth_token_and_setargs_cb_none);
}
set_azauth_res_callback(set_azauth_res_sc_cb);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this one also


/*
* Initialize nfs_client singleton.
Expand Down