You can do that with field level security.
https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/admin/field-level-security
You need to first define the fields to be secure on field configuration in CDS.
Then configure field security profiles based on roles. Note this is not yet in the modern settings experience, so you need to go to advanced settings to manage your field security profiles
from classic settings go to Security-->Field Security Profiles.
create field security profile for the role(s)
set security setting for fields. the permissions available are:
Read. Read-only access to the field’s data.
Create. Users or teams in this profile can add data to this field when creating a record.
Update. Users or teams in this profile can update the field’s data after it has been created.
A combination of these three permissions can be configured to determine the user privileges for a specific data field.
Note--this doesn't hide the field or sections on the form, but it secures the data at the platform layer, so no matter how people interact with the data (reports, model apps, canvas apps, excel output, etc) that will not see the data.
If you want to selectively hide the field on a form based on role, you need to use JavaScript.