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

Ability to add NAS Identifier attribute to radius request #5465

Merged
merged 1 commit into from
Oct 18, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions builtin/credential/radius/path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func pathConfig(b *backend) *framework.Path {
Default: 10,
Description: "RADIUS NAS port field (default: 10)",
},
"nas_identifier": &framework.FieldSchema{
Type: framework.TypeString,
Default: "",
Description: "RADIUS NAS Identifier field (optional)",
},
},

ExistenceCheck: b.configExistenceCheck,
Expand Down Expand Up @@ -110,6 +115,7 @@ func (b *backend) pathConfigRead(ctx context.Context, req *logical.Request, d *f
"dial_timeout": cfg.DialTimeout,
"read_timeout": cfg.ReadTimeout,
"nas_port": cfg.NasPort,
"nas_identifier": cfg.NasIdentifier,
},
}
return resp, nil
Expand Down Expand Up @@ -190,6 +196,13 @@ func (b *backend) pathConfigCreateUpdate(ctx context.Context, req *logical.Reque
cfg.NasPort = d.Get("nas_port").(int)
}

nasIdentifier, ok := d.GetOk("nas_identifier")
if ok {
cfg.NasIdentifier = nasIdentifier.(string)
} else if req.Operation == logical.CreateOperation {
cfg.NasIdentifier = d.Get("nas_identifier").(string)
}

entry, err := logical.StorageEntryJSON("config", cfg)
if err != nil {
return nil, err
Expand All @@ -209,6 +222,7 @@ type ConfigEntry struct {
DialTimeout int `json:"dial_timeout" structs:"dial_timeout" mapstructure:"dial_timeout"`
ReadTimeout int `json:"read_timeout" structs:"read_timeout" mapstructure:"read_timeout"`
NasPort int `json:"nas_port" structs:"nas_port" mapstructure:"nas_port"`
NasIdentifier string `json:"nas_identifier" structs:"nas_identifier" mapstructure:"nas_identifier"`
}

const pathConfigHelpSyn = `
Expand Down
3 changes: 3 additions & 0 deletions builtin/credential/radius/path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func (b *backend) RadiusLogin(ctx context.Context, req *logical.Request, usernam
packet := radius.New(radius.CodeAccessRequest, []byte(cfg.Secret))
UserName_SetString(packet, username)
UserPassword_SetString(packet, password)
if cfg.NasIdentifier != "" {
NASIdentifier_AddString(packet, cfg.NasIdentifier)
Copy link
Member

Choose a reason for hiding this comment

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

Given that some of the other variables are choosing Set functions, is there a reason for choosing NASIdentifier_AddString over NASIdentifier_SetString? Will adding allocate the space needed?

Copy link
Member

Choose a reason for hiding this comment

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

Using Add allows multiple. I don't think it matters here though since we're only supporting a single identifier (at least for now). But if we ever supported more than one we'd need to iterate over and use Add, so makes sense to keep it in for now I think.

}
packet.Add(5, radius.NewInteger(uint32(cfg.NasPort)))

client := radius.Client{
Expand Down
6 changes: 5 additions & 1 deletion ui/app/models/auth-config/radius.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ export default AuthConfig.extend({
label: 'NAS Port',
}),

nasIdentifier: attr('string', {
label: 'NAS Identifier',
}),

fieldGroups: computed(function() {
const groups = [
{
default: ['host', 'secret'],
},
{
'RADIUS Options': ['port', 'nasPort', 'dialTimeout', 'unregisteredUserPolicies'],
'RADIUS Options': ['port', 'nasPort', 'nasIdentifier', 'dialTimeout', 'unregisteredUserPolicies'],
},
];
return fieldToAttrs(this, groups);
Expand Down